Python Membership operator
Python membership operator are used to check, whether a sequence or values are present in an object.
For example, to check whether 'h' is present in the string 'Hello world', we make use of 'in' operator.
Operator | Operation |
---|---|
in | Returns True if a sequence/value is present in an object |
not in | Returns True if a sequence/value is not present in an object |
Python 'in' and 'not in' membership operator
In Python, to check if a value or a sequence is present in an object, we make use of 'in' membership operator.
And 'not in' to find if a sequence/value is not present in an object.
Program
>>> st = "Hello world!"
>>> 'H' in st
True
>>> 'world' in st
True
>>> "Sleep" in st
False
>>> "Sleep" not in st
True
>>> 'Hello' not in st
False
إرسال تعليق
If you have any query, feel free to ask.