Note the documentation __contains__,
. true, item self, - false. , .
, __contains__(), __iter__(), __getitem__()
, , in, :
print("hello" in hippo)
: Python 3.x __getslice__. Python 3.0,
__getslice__(), __setslice__() __delslice__() . a[i:j] a.__getitem__(slice(i, j)) ( __setitem__() __delitem__(), ) .
, .
, .
. True, hippo.capitalize() . , self._string HELLO WORLD, . , False.
1: Python True False. __contains__ True, NameError . .
def __contains__(self, word):
return word in self._string
2: __getslice__
def __getslice__(self, start, end):
return self[max(0, i):max(0, j):]
i j, . , start end,
def __getslice__(self, start, end):
return self[max(0, start):max(0, end):]