Why does every string contain the empty string?

后端 未结 2 1930
故里飘歌
故里飘歌 2021-01-22 14:47

\"ABCDE\" has no empty character. But when I type

\"\" in \"ABCDE\"

Python interpreter returns True.

Why?

is there

2条回答
  •  囚心锁ツ
    2021-01-22 15:19

    Here's a qualitative way to think about it. Consider the following:

    >>> "foo"[0:0]
    ''
    

    Doing a zero-width slice of a string returns ''. So, if you can get '' out of a string, it must be in the string and therefore '' in "foo" must be true.

提交回复
热议问题