Working with Lists in Python - Tutorial Image Working with Lists in Python - Tutorial

This tutorial was built in Python 3.6

A Simple List

my_list = [1, 2, 3, 4] 

Reversing a List

This quick and easy technique shows how you can access all the elements of a list in reverse order.

>>> my_list = [1,2,3,4,5]
>>> my_list[::-1]
[5, 4, 3, 2, 1]

Try it Out

my_list = [1, 2, 3, 4] 

We can then treat our reversed list as an iterator and iterate through every element within this reversed list like so:

>>> for el in my_list[::-1]:
...     print(el)


If you found this tutorial useful or require further assistance then please let me know in the comments section below or by tweeting me: @Elliot_F.

Elliot Forbes

Elliot Forbes
Twitter: @Elliot_f

Hey, I'm Elliot and I've been working on TutorialEdge for the last 4 years! If my work has helped you in any way, shape, or form then please consider supporting my work.

become a patron Buy Me A Coffee