+ 1

Two questions:1, Strings is more similar with tuple ? 2, Why is false ?

1, Lists and strings are similar in many ways - strings can be thought of as lists of characters that can't be changed. 2, The in operator is also used to determine whether or not a string is a substring of another string. A=["spam",["eggs","sandwich"]] Print ("eggs" in A) -> false Print ("eggs" in A[1]) -> true Why???

24th Jul 2020, 4:16 PM
吳宗原
吳宗原 - avatar
3 Respostas
+ 2
Answer to your second question, the list A has two elements "spam" and ["eggs","sandwich"] ,if u execute "eggs" in A it returns false because in is membership operator and A do not have any element "eggs" in it. **in compares the elemets as a whole **
26th Jul 2020, 4:08 PM
Rajneesh Singh
Rajneesh Singh - avatar
+ 3
A string stores characters only (despite of encoding) A tuple stores any type, including (among which) tuples, strings and other types.
24th Jul 2020, 4:31 PM
Ipang
+ 2
Thanks to you two guys
27th Jul 2020, 5:23 AM
吳宗原
吳宗原 - avatar