Why output of this code is 'false'? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why output of this code is 'false'?

x = [ 1,3,5 ] print (x in x)

22nd Feb 2020, 4:29 PM
Peter Parker
Peter Parker - avatar
4 Answers
+ 5
Because the list is not a member of itself, only elements inside are members of the list.
22nd Feb 2020, 4:49 PM
Mihai Apostol
Mihai Apostol - avatar
+ 3
Alexandr Next question will be what is [...], because you just created a self-referencing list 😉 WhyFry Good example...
22nd Feb 2020, 4:58 PM
Mihai Apostol
Mihai Apostol - avatar
+ 2
[not answer] [off-topic] Hari Shankar As continuation of Alexandr's example check this out. https://code.sololearn.com/cC6sIz1KO4ax/?ref=app
22nd Feb 2020, 5:08 PM
Mihai Apostol
Mihai Apostol - avatar
+ 1
x = [1, 3, 5] x.append(x) print(x in x) Output of this is true
22nd Feb 2020, 5:11 PM
Peter Parker
Peter Parker - avatar