Bad example in Chapter 3 of Python 2.6.5 Tutorial
Hi there. This should be easy to fix, and I may be wrong (I'm just learning Python), but I believe the behavior of negative list (in this case, string) indices is such that a[-1] returns the *last* element, not the second-last. However, near the bottom of the Strings section of Chapter 3 of the official tutorial (link <http://docs.python.org/tutorial/introduction.html#strings>) is a section and table regarding this, conflicts with itself: the ASCII table near the very bottom lists the indices wrong! Thank you for your help, and I do apologize if I am mistaken, but I'm fairly sure I'm right. :)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 10.06.2010 07:30, schrieb Dylan Laufenberg:
Hi there.
This should be easy to fix, and I may be wrong (I'm just learning Python), but I believe the behavior of negative list (in this case, string) indices is such that a[-1] returns the /last/ element, not the second-last. However, near the bottom of the Strings section of Chapter 3 of the official tutorial (link <http://docs.python.org/tutorial/introduction.html#strings>) is a section and table regarding this, conflicts with itself: the ASCII table near the very bottom lists the indices wrong!
Thank you for your help, and I do apologize if I am mistaken, but I'm fairly sure I'm right. :)
Hi Dylan, I'm not sure right now which table you refer to; if it's this one +---+---+---+---+---+ | H | e | l | p | A | +---+---+---+---+---+ 0 1 2 3 4 5 -5 -4 -3 -2 -1 then it is correct; as with the positive indices, the index is placed on the left of the item it refers to, as you have to give this index as the stop index if you want your slice to stop before the character (remember this table is for understanding slice notation). regards, Georg -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) iEYEARECAAYFAkwTKikACgkQN9GcIYhpnLCQHwCfUFxkazcEFlAzjFN4osxHL8S7 15MAnAtwE1U/IAsWWP9SibrVPKrM6t3j =33GH -----END PGP SIGNATURE-----
participants (2)
-
Dylan Laufenberg
-
Georg Brandl