0

Slice a list in python

Please let me know, can we slice a list in python if the initial position is equal to termination position? For example: Lst = list(range(10)) print(Lst[4:4:2]

25th Jul 2024, 10:40 PM
Oliver Pasaribu
4 odpowiedzi
+ 3
Why don’t you try it yourself and see?
26th Jul 2024, 1:42 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 2
Apart from missing closing parentheses which could be a typo, it just doesn't make sense. Slicing a `list` from 4th index and excludes the 4th index. What you have in mind with this thought though?
26th Jul 2024, 7:31 AM
Ipang
+ 2
Yes, it is possible to do, it will be an empty slice. You can also write a for loop which is never executed.
26th Jul 2024, 8:11 AM
Tibor Santa
Tibor Santa - avatar
0
I think you should try directly on editor or your console all possibilities of slicing a list in Python, also you can use the slice with elements sequenced like string, tuple, list, etc..
27th Jul 2024, 4:30 PM
Harimamy Ravalohery
Harimamy Ravalohery - avatar