Python List sort() MethodPython sort() method sorts the list elements. It also sorts the items into descending and ascending order. It takes an optional parameter 'reverse' which sorts the list into descending order. By default, list sorts the elements into ascending order. The examples and signature are given below. SignatureParametersNo parameter ReturnIt returns None. Let's see some examples of sort() method to understand it's functionality. Python List sort() Method Example 1It is a simple example which sorts two lists in ascending order. See the example below. Output: ['a', 'p', 'p', 'l', 'e'] [6, 8, 2, 4] After Sorting: ['a', 'e', 'l', 'p', 'p'] [2, 4, 6, 8] Python List sort() Method Example 2This example sorts the list into descending order. Output: [8, 6, 4, 2] Python List sort() Method Example 3This example sorts the char list into descending order. Output: ['a', 'p', 'p', 'l', 'e'] [6, 8, 2, 4] After Sorting: ['p', 'p', 'l', 'e', 'a'] [8, 6, 4, 2]
Next TopicPython Lists
|
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week