Ads by ProfitSence

How to reverse a list in Python Code Example

Last Updated on Wednesday 5th Oct 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']


And the result we get

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


Example 2

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



And the result we get

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