How to reverse a list in Python Code Example

Last Updated On Thursday 20th Jan 2022

What is a list?

List in python is a data structure that is used to store multiple values in a variable.

When should a list be used?

  • Store duplicate values in a list
  • Insertion order must be preserved.

List Examples

  • Empty List: l = [ ]
  • List with data set: datas = [10, 20, 30, 40, 50]

Let’s say we have a list, and we want to flip it into reverse order.

Example 1

	names = ['adam', 'alice', 'jury', 'matt']
names.reverse()
print(names)
	

And the result we get

	['matt', 'jury', 'alice', 'adam']
	

Example 2

	names = ['agar', 'broad', 'carry', 'deone']

print(names[::1])
	

And the result we get

	['deone', 'carry', 'broad', 'agar']