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

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

1

u/Invader_Mars Sep 26 '24

Your comment made it clear as day. Cool idea on all this, TIL. Thanks