Tuesday, December 23, 2014

More on lists

We will extend our study on list:

>>>list= [2,3,4,5,"Hello",6]

>>>print list[-1:-3]
[]
>>>print list[-3:-1]
[5,'Hello']
>>>print list[-4:]
[5,'Hello',6]
>>>print list[1:]
[3,4,5,'Hello',6]
>>>print list[:]
[2,3,4,5,'Hello',6]

">>>list[para1:para2:para3]"
'''
Here you can see that we have three parameters namely para1, para2, para3.
para1-> first parameter from where our operation on list will start.
para2-> second parameter onto which our operation on list will end (ofcourse excluding that index location)
para3->third parameter also known as step parameter which decides how many index location to jump each time during operation
'''
>>>print list[1:4:2]
[3,5]
>>>print list[0:5:3]
[2,5]

# we can also use this feature to reverse the list
>>>print list[::-1]
[6,'Hello',5,4,3,2]






No comments:

Post a Comment