+ 2
Could any one give the examples of membership operator(in , not in) by using list , tuples, dictionary
9 ответов
+ 2
List->[]
Tuple->()
Dictionary->{}
I learn this☹️
+ 1
Dear () ,{},[]
+ 1
What it means?
+ 1
Tomiwa Joseph thank you
Could you give tuple example
+ 1
Ok thank u soo much
0
a_list = [1,3,4,5,6]
If 3 in a_list:
print('it is there')
elif 2 not in a_list:
print('it is not there')
Note: for dictionaries, the in and not in works with the dict key unless specified to check the dict values. For example:
a_dict = {1:7,3:2}
if 2 in a_dict:
print('yes')
else: print('no')
Output will be NO!
Unless...
if 2 in a_dict.values():
print('yes')
else: print('no')
Hope this helps.
0
It's Me it is the same as list
a_tuple = (1,3,4,5)
if 2 in a_tuple:
print('yes')
else: print('no')
Output: no
0
It's Me it is the same as list
a_tuple = (1,3,4,5)
if 2 in a_tuple:
print('yes')
else: print('no')
Output: no