I don’t understand why not empty strings are False, same like empty strings. I think that collection of characters is much something than less. What is a root of python purpose in this case?
>>> "" in 'fdsa'
True
>>> '' in ''
True
>>> 'asdf' in ''
False
>>> 'adsf' is True
False
I don’t quite get your question. You are using two operators here:
infor strings checks whether the first string is a substring of the second. The empty string is considered a substring of every other string.istests for object identity and returnsTrueif both operators are the same object.'adsf'andTrueclearly aren’t the same object, so you getFalse.None of those two operators are related to interpreting strings in a Boolean context – something your question also seems to touch on. A Boolean context would be the condition of an
ifstatement, for example. In a Boolean context, empty strings are treated asFalse, and non-empty strings asTrue. You can see how an object behaves in a Boolean context by usingbool(obj).