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

Show parent comments

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')

10

u/wildpantz Sep 26 '24

Actually, one could argue there's infinite "" in "abc", just how 3 can be expressed as 2+1 but also as 2+1+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0.

Just because something doesn't make sense to you, doesn't mean it doesn't make sense.

3

u/zefciu Sep 26 '24

I think it is the best explanation. If you concatenate strings, it would be silly if you no longer could find the concatenated strings in the results. So it makes sense that you can find '' in 'a' + '' + 'bc'.