What are the methods of python operation list
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!