python list index - an easy question
John
miaojpm at gmail.com
Sat Dec 17 14:10:22 EST 2016
Hi,
I am new to Python, and I believe it's an easy question. I know R and Matlab.
************
>>> x=[1,2,3,4,5,6,7]
>>> x[0]
1
>>> x[1:5]
[2, 3, 4, 5]
*************
My question is: what does x[1:5] mean? By Python's convention, the first element of a list is indexed as "0". Doesn't x[1:5] mean a sub-list of x, indexed 1,2,3,4,5? If I am right, it should print [2,3,4,5,6]. Why does it print only [2,3,4,5]?
Thanks!!
John
More information about the Python-list
mailing list