Ad

Thursday, October 5, 2017

Python Interview List Slicing

a = [1,2,3,4] 
a[0:3] 
-> [1, 2, 3] 

 a[0:3:2] # slice with increment of 2 
->[1, 3] 

 a[::-1] # reverse slicing 
->[4, 3, 2, 1] 

 t=(1,2,3,4,5) #slicing tuples 
t[0:4] 
->(1, 2, 3, 4) 

 t=(1,2,3,4,5) 
sliceObj = slice(1,3) 
t[sliceObj] ->(2, 3)

t[:]
-> returns a full copy of the list

No comments:

Post a Comment

Getting Started Coding Amazon Alexa Skills for Developers

Getting Started First read our blog post on how to get started with Alexa Skill building or watch our youtube video on the topic Blog...