You can see "python"
as "the empty string, followed by a p
, followed by fifteen more empty strings, followed by a y
, followed by forty-two empty strings, ...".
Point being, empty strings don't take any space, so there's no reason why it should not be there.
The index
method could be specified like this:
s.index(t)
returns a value i
such that s[i : i+len(t)]
is equal to t
If you substitute the empty string for t
, this reads: "returns a value i
such that s[i:i]
is equal to ""
". And indeed, the value 0
is a correct return value according to this specification.