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

53

u/Binary101010 Sep 26 '24

Directly from the Python docs:

Empty strings are always considered to be a substring of any other string, so "" in "abc" will return True.

https://docs.python.org/3/reference/expressions.html#membership-test-operations

0

u/[deleted] Sep 26 '24

[deleted]

-77

u/my_password_is______ Sep 26 '24

oh come on

that is NOT a good reason for a programming language

you can LITERALLY see '' is NOT in 'abc'

using standard set theory you end up with stupid shit like this

if '' in 'abc' and '' in 'def' :              
    print('this is stupid')

44

u/aplarsen Sep 26 '24

Found the angsty teen who doesn't like math