I am somewhat of a python/programming newbie, and I have just been playing around with string slicing. So the simple string reverse method of string[::-1]
works just fine as we know, but there are other instances in my code below that yields unexpected results:
In [1]: string = "Howdy doody"
In [2]: string[::]
Out[2]: 'Howdy doody'
In [3]: string[::-1]
Out[3]: 'ydood ydwoH'
In [4]: string[0:]
Out[4]: 'Howdy doody'
In [5]: string[0::-1]
Out[5]: 'H' # what up with this?
In [6]: string[:len(string)]
Out[6]: 'Howdy doody'
In [7]: string[:len(string):-1]
Out[7]: '' # what up with this too?
In [8]: string[0:len(string)]
Out[8]: 'Howdy doody'
In [9]: string[0:len(string):-1]
Out[9]: '' # And what up here too.
I have commented on the lines above where I expected the strings to be reversed, but I am surprised to see why they don't simply reverse the string. Anyone know what is up with that?