in , not in ( Membership Operators)

x in my_iterable
my_iterable : iterable input.
Return boolean value True or False. If x is found inside my_iterable then True is returned otherwise False.

x not in  my_iterable
my_iterable : iterable input.
Return boolean value True or False. If x is found inside my_iterable then False is returned otherwise True.

Using list

More on list

Example
my_list=[3,4,5,8,3]
if(5 in my_list):
  print("Yes it is Present")
else:
  print("NO  it is NOT Present")  
Output
Yes it is Present
Example:
my_list=[3,4,5,8,3]
if(9 in my_list):
  print("Yes it is Present")
else:
  print("NO  it is NOT Present")  
Output
NO  it is NOT Present

Example using not in

my_list=[3,4,5,8,3]
if(9 not in my_list):
  print("Yes it is NOT Present")
else:
  print("NO  it is  Present")
Output
Yes it is NOT Present

Using For Loop and range

for i in range (0,5):
  print(i,end=',')
Output
0,1,2,3,4,

Using string

url='plus2net.com'
if( '2' in url):
  print("yes 2 is available inside")
else:
  print("No 2 is not available inside ") 
Output
yes 2 is available inside
We will use Dictionary

Output depends on Keys of the Dictionary ( Not Values ). If any one of the key present then in returns True otherwise False
my_dict={0:'A',1:'B'}
print(1 in my_dict) # True
my_dict={0:'A',1:'B'}
print('A' in my_dict) # False
my_dict={'A':'X','B':'Y','C':'Z'}
print('X' in my_dict)     # False
print('C' in my_dict)     # True
print('Y' not in my_dict) # True
We will use tuple
my_tuple=(6,1,12,7)
print(7 in my_tuple) # True
my_tuple=(6,1,12,7)
print(8 not in my_tuple) # True
is and not is: The Identity operators Iterator any()

Your Rating




Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer