Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of python operation list

Shulou Source: shulou.com Published: 2022-06-03 13:50:10 10月13日 Update

Editor to share with you what are the methods of the python operation list, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Use sort to permanently sort the list.

Names = ["Tom", "Jerry", "Bob", "Ann"] print (names) names.sort () # ascending sort print (names) # output:# ['Tom',' Jerry', 'Bob',' Ann'] # ['Ann',' Bob', 'Jerry',' Tom']

2. Use sorted to temporarily sort the list.

Names = ["Jerry", "Tom", "Bob", "Ann"] print (names) print (sorted (names)) print (names) # does not change # output:# ['Jerry',' Tom', 'Bob',' Ann'] # ['Ann',' Bob', 'Jerry',' Tom'] # ['Jerry',' Tom', 'Bob',' Ann']

3. Reverse the list element reverse. This modification is permanent. If you want to restore it, just call it again.

Names = ["Jerry", "Tom", "Bob", "Ann"] print (names) names.reverse () # whole reverse print (names) # output:# ['Jerry',' Tom', 'Bob',' Ann'] # ['Ann',' Bob', 'Tom',' Jerry']

4. Determine the length of the list len.

Names = ["Jerry", "Tom", "Bob", "Ann"] print (len (names)) # output:# 4 are all the contents of this article entitled "what are the methods of python operation list". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Articles sorting methods content permanent not so elements ascending most more permanent knowledge industry information information channels length channels reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei NVidia Redmi OPPO Reno MariaDB