Confusion in 'in' operator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Confusion in 'in' operator

What is the output of num=[1,2,[3,4],5] print(3 in num) please tell the output with reason. how to get "true" in the answer?

26th Dec 2016, 11:53 AM
AMAN AGARWAL
AMAN AGARWAL - avatar
1 Answer
+ 2
The output would be "False". In the list "num", we don't have the number 3. We have the number 3 in a list nested within the list "num". So, using the "in" operator, you can check whether a list has a specific value.
26th Dec 2016, 12:30 PM
Tanvir Ahmed
Tanvir Ahmed - avatar