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

What is a Neural Network - Best Machine Learning Tutorials

Neural networks are important for ML as well as artificial intelligence and deep learning. This Youtube channel explains NN in depth. Take a...