

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to sort the elements of an array in ascending order
When it is required to sort the elements of an array in ascending order, the ‘sort’ method can be used. It helps sort the elements in ascending order by default. If we want it to be sorted in descending order, a parameter named ‘reverse’ can be set to True.
Below is a demonstration of the same −
Example
my_list = [44, 56, 42, 31, 11, 23, 78, 89, 9, 0] print("The list is :") print(my_list) my_list.sort() print("The list after sorting is :") print(my_list)
Output
The list is : [44, 56, 42, 31, 11, 23, 78, 89, 9, 0] The list after sorting is : [0, 9, 11, 23, 31, 42, 44, 56, 78, 89]
Explanation
A list is defined, and is displayed on the console.
The ‘sort’ method is called on the list.
The output is displayed on the console.
A list is defined, and is displayed on the console.
The ‘sort’ method is called on the list.
The output is displayed on the console.
- Related Questions & Answers
- C program to sort an array of ten elements in an ascending order
- C program to sort an array in an ascending order
- 8086 program to sort an integer array in ascending order
- Java Program to Sort Array list in an Ascending Order
- How to sort Java array elements in ascending order?
- Python program to sort the elements of an array in descending order
- Python program to sort out words of the sentence in ascending order
- Program to sort each diagonal elements in ascending order of a matrix in C++
- Java program to sort words of sentence in ascending order
- How do you sort an array in C# in ascending order?
- 8085 Program to perform bubble sort in ascending order
- 8085 Program to perform selection sort in ascending order
- Python program to print the elements of an array in reverse order
- Program to merge intervals and sort them in ascending order in Python
- Sort index in ascending order – Python Pandas
Advertisements