I know Pythonic slicing : l1[start:stop:step].
What’s the use of built-in function slice?
How can I use it ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You create a slice by calling slice with the same fields you would use if doing [start:end:step] notation:
To use the slice, just pass it as if it were the index into a list or string:
Let’s say you have a file of fixed-length text fields. You could define a list of slices to easily extract the values from each "record" in this file.
Prints: