Sort Python List Ascending: Quick Guide

You can sort Python list data in ascending order by using the sort() method of the list or by using the built-in function sorted().

Use the sort() method:

my_list = [4, 2, 1, 5, 3]
my_list.sort()
print(my_list)

Use the sorted() function:

my_list = [4, 2, 1, 5, 3]
sorted_list = sorted(my_list)
print(sorted_list)

Both methods will sort the elements in the list in ascending order.

bannerAds