+ 2

Could any one give the examples of membership operator(in , not in) by using list , tuples, dictionary

6th Jul 2020, 8:30 AM
Sufia Hashmi
Sufia Hashmi - avatar
8 odpowiedzi
+ 2
List->[] Tuple->() Dictionary->{} I learn this☹️
6th Jul 2020, 8:54 AM
Sufia Hashmi
Sufia Hashmi - avatar
+ 1
Dear () ,{},[]
6th Jul 2020, 8:39 AM
Sufia Hashmi
Sufia Hashmi - avatar
+ 1
What it means?
6th Jul 2020, 8:39 AM
Sufia Hashmi
Sufia Hashmi - avatar
+ 1
Tomiwa Joseph thank you Could you give tuple example
6th Jul 2020, 8:45 AM
Sufia Hashmi
Sufia Hashmi - avatar
+ 1
Ok thank u soo much
6th Jul 2020, 11:55 AM
Sufia Hashmi
Sufia Hashmi - avatar
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.
6th Jul 2020, 8:42 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
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
6th Jul 2020, 8:52 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
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
7th Jul 2020, 9:58 PM
Amitabh Pandey
Amitabh Pandey - avatar