 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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.
Advertisements
 