List Methods in Python - in, not in, len(), min(), max()


In this article, we will learn about various types of list methods available to us in Python 3.x. Or earlier. These operators allow us to perform the basic operations on the list content.

In & Not in operators

  • “in” operator  − This operator is used to check whether an element is present in the passed list or not. Returns true if the element is present in the list otherwise returns false.

  • “not in” operator  − This operator is used to check whether an element is not present in the passed list or not. Returns true if the element is not present in the list otherwise returns false. Let’s take a look at the example to understand it better.

Example

lis = ['t','u','t','o','r','i','a','l']
# in operator
if 't' in lis:
   print ("List is having element with value t")
else :
   print ("List is not having element with value t")
# not in operator
if 'p' not in lis:
   print ("List is not having element with value p")
else :
   print ("List is having element with value p")

Output

List is having element with value t
List is not having element with value p

Len() , Max() & Min() operators

  • len()  − This function returns the length of list. If the object has no asssociation with length , error is raised .

  • min() − This function returns the minimum element from the list.

  • max()  − This function returns the maximum element from the list.

Let’s take a look at the example to understand it better.

Example

lis = ['t','u','t','o','r','i','a','l']

# len()
print ("The length of list is : ", end="")
print (len(lis))

# min()
print ("The minimum element of list is : ", end="")
print (min(lis))

# max()
print ("The maximum element of list is : ", end="")
print (max(lis))

Output

The length of list is : 8
The minimum element of list is : a
The maximum element of list is : u

Conclusion

In this article, we learnt how to implement in and not in operators along with len(), max(), & min() method.

Updated on: 01-Jul-2020

17K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements