Skip to main content


That:

a in ('a,' 'b',)

… is legal #Python is very unfortunate.

in reply to Christophe

which part? that a tuple is a sequence? the trailing comma?

IMO it's much more unfortunate that strings are sequences, so

'a' in "flab"<br>

is True
in reply to ilmari

@ilmari I think they both fall under the category of "certain combinations of useful features end up with situations that seem like bugs." Having multiple string literals in a row concatenate is useful, and having a single-item tuple is useful, but you can stare at why 'a' in ('a,' 'b',) for a long time before you realize why it's false.
in reply to Christophe

D'oh, I missed that the comma was on the wrong side of the closing quote, proving your point! That is an unfortunate C-ism they've copied. At least SQL only lets you do that when splitting a string across multiple lines.