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

-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

58

u/Jello_Penguin_2956 Sep 26 '24

I disagree. I can see that empty string before a, between a b c, and after c.

Its not a space

26

u/a2242364 Sep 26 '24

if you took intro to set-theory/discrete maths/theory of computation, you would know that this makes complete sense.

12

u/[deleted] Sep 26 '24

‘’ is in ‘abc’. Are you confusing it with ‘ ‘?

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

9

u/fivepython Sep 26 '24

I highly recommend looking up what the null set is, because it might be confusing at first but it’s a result of an axiom of math, aka, professionally agreed upon

5

u/skeleton_craft Sep 26 '24

I mean that working literally is a cornerstone of modern math, and number theory. I don't think you fully understand what it is exactly you're complaining about.

1

u/TabsBelow Sep 26 '24

What do YOU see between the A and the B , resp B and C?

Nothing? Yep. You're going to find the conclusion.