Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # slicing
- x = [1, 2, 3, 4, 5, 7]
- x1 = x[1:3] # elements between 1 to 3
- print(x1) # ans: [2,3]
- x2 = x[:4] # elements till 5
- print(x2) # ans: [1,2,3,4]
- x3 = x[3:-1]
- print(x3) # ans: [4,5]
- x4 = x[:-5]
- print(x4) #ans: [1]
- x5 = x[1:6:2] # skip 1 index every time
- print(x5) # [2,4,7]
- x6 = x[::-1] # reverse the list
- print(x6)
Advertisement
Add Comment
Please, Sign In to add comment