Membership Operators:
>>> a="Hello
Good morning!!"
>>>
print("H" in a) #True
>>> print('h' in a) #False
>>> print('k' not in
a) #True
>>> print('good' in
a) #False
>>> print('Good' in
a)#True
>>>
print("Afternoon" in a) #False
>>> print(a in a) #True,
this is not the right way as to be searched object should be in single/double
quote
>>> print(b in a)
#Error
Example 2:
>>>
b=["Hyd","Kadapa","Vij",'Blore']
>>> type(b)
<class 'list'>
>>>
print("Hyd" in b) #True
>>>
print("Delhi" in b) #False
>>>
print("Kur" not in b) #True
>>>
The membership operators are
used to check whether the given object present in the given Collection (List,
Tuple,String, Set or Dict.)
There are two membership
operators are available:
in
not in
inàreturns True if the given object present in the
specified collection
not
inàit returns True if the given object not present
in the specified collection.
Related Video: https://youtu.be/xBNdZ2ytTiU
Next topic: Bitwise
OperatorsPrevious Topic: Special Operators
No comments:
Post a Comment