I am wanting to find the resource doc on “slicing” for python (i.e. “:”) but I can’t seem to find it. It isn’t under Docs/Python/List. Anyone know where I can find the resource doc for slicing in python on codecademy? Thanks!
While not aware of any such resource, the process of slicing is very simple and straight forward, and sharing the STOP value property with range()
.
range(start (inclusive), stop (exclusive), step)
print (list(range(1, 11, 2))) # [ 1, 3, 5, 7, 9 ]
Notice there is no 11
in that sequence?
alist[start (inclusive) : stop (exclusive) : step]
alist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11][0:10:2]
print (alist) # [ 1, 3, 5, 7, 9 ]
Ping this topic if you wish to go into greater detail on such things as optional parameters, reversing and so on.
3 Likes
https://www.codecademy.com/resources/docs/python/substrings
Here are a few other examples of slicing:
https://discuss.codecademy.com/t/faq-working-with-lists-in-python-slicing-lists/371504/12
3 Likes
Perfect , thank you so much.
2 Likes
Thank you for helping
3 Likes
Thank you for taking the time to help
2 Likes