What is Python list sorting
This article mainly explains "what is the sort of Python list". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what is the sort of Python list.
In Python, there are two ways to sort lists.
One is to call the sort () method, which returns no value and sorts the list itself in ascending order.
Cars = ['bmw',' audi', 'toyota',' subaru'] cars.sort () print (cars)
Output:
['audi',' bmw', 'subaru',' toyota']
Another way is to use the sorted () function, which returns the list sorted in ascending order without affecting the original list.
Cars = ['bmw',' audi', 'toyota',' subaru'] print ("Here is the original list:") print (cars) print ("\ nHere is the sorted list:") print (sorted (cars)) print ("\ nHere is the original list again:") print (cars)
Output:
Here is the original list: ['bmw',' audi', 'toyota',' subaru'] Here is the sorted list: ['audi',' bmw', 'subaru',' toyota'] Here is the original list again: ['bmw',' audi', 'toyota',' subaru'] Thank you for reading. That's what Python list sorting is. After the study of this article, I believe that you have a deeper understanding of what is the sort of Python list, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!