Followers

Monday, August 22, 2016

Python Oddity

Here is a Python oddity that I discovered while teaching students.

If negative indexing should work right,

then for a string m='string',


>>> m='string'
>>> m[:-1]
'strin'
>>> m[:0]
''
>>> m[-1]
'g'
>>> m[0:]
'string'
>>> m[:-1]
'strin'
>>> m[:0]
''
>>>

I want to know how to access the entire string using the negative index?

No comments :

Post a Comment