Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python negative subscripting

I'm currently reading Robert Sebesta's Concepts of Programming Languages, 10th edition (2012). In the chapter about data types, it reads "Ruby and Lua support negative subscripts, but Python does not". I thought negatives subscripts could be done in Python using list_name[-i]. What are negative subscripts then?

like image 907
Felipe Cortez Avatar asked Mar 02 '14 17:03

Felipe Cortez


1 Answers

Python, Lua, and Ruby support negative subscripts. In Python, this feature was added as a footnote in version 1.4 and reaffirmed as extended slicing in version 2.3

On p.264 of Sebesta's book (10th ed.) he claims Python does not support negative indexing on arrays. The original text was overhauled and republished as edition 6 in 2004, while Python 2.3 was released on July 29, 2003. I'm guessing extended slicing was overlooked and been in error since the release of Sebesta's 6th edition.

I cannot find errata for the 10th edition. You may want to email the author and inform him.

like image 171
Myles Baker Avatar answered Oct 06 '22 01:10

Myles Baker