Sunday, 27 December 2020

Python: in: Check for existence of element in the list

‘in’ keyword is used to check for the existence of an element in the list.

 

Syntax

element in list

 

Example

10 in first_5_primes

 

Above statement return True, if 10 is in first primes list, else False.

>>> first_5_primes = [2, 3, 5, 7, 11]
>>> 
>>> 10 in first_5_primes
False
>>> 
>>> 11 in first_5_primes
True

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment