When using the interpreter, the expression 'a' in ('abc') returns True, while 'a' in ['abc'] returns False. Can somebody explain this behaviour?
('abc') is the same as 'abc'. 'abc' contains the substring 'a', hence 'a' in 'abc' == True.
If you want the tuple instead, you need to write ('abc', ).
['abc'] is a list (containing a single element, the string 'abc'). 'a' is not a member of this list, so 'a' in ['abc'] == False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With