Thursday, January 17, 2013

get element, sublist and length of a list using python


d = range(10)
>>> d
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


>>> d[9]
9


>>> d[-1]
9


>>> d[0:9]
[0, 1, 2, 3, 4, 5, 6, 7, 8]


>>> d[0:-1]
[0, 1, 2, 3, 4, 5, 6, 7, 8]


>>> len(d)
10

0 comments:

Post a Comment