r/learnpython • • Sep 26 '24

Empty strings - am i tripping?

>>> '' in 'abc'
True

can someone explain? (python 3.12.6)

1 Upvotes

27 comments sorted by

View all comments

15

u/theWyzzerd Sep 26 '24 edited Sep 26 '24

Why would this not be true? Every string has an empty string in it. If "" is in "" why shouldn't it also be in "a"?

Think of it this way -- if a string is the set of characters "abc" what are you left with if you drop "a" and "b" and "c" from the string? You're left with "", which means it was in string "abc" all along.