In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to analyze the python list, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can gain something through the detailed introduction of this article.
1. List
Instead of arrays, python introduces lists (list), which can store any type of data, and the data types in the same list can be different.
List when the sequence structure, you can carry out the basic operations of the sequence structure, such as indexing, fetching substrings, addition, multiplication and so on.
two。 Use format
When you create a new list, put all the elements in the list in square brackets, and the adjacent elements are separated by commas (the data type can also be different ha ~)
Str = [10,2.4, 'lmy'] print (str [0]) print (str [1]) print (str [2])' 'output:102.4lmy'''
You can also update the existing elements of the list, using the function append ()
Str = [10,2.4, 'lmy'] str [1] = 5str.append (' good') print (str) 'output: [10,5,' lmy', 'good']''
Delete the element, using the del () function
Str = [10,2.4, 'lmy'] str [1] = 5str.append (' good') del str [0] print (str)''output: [5,' lmy', 'good']''3. Some very useful functions
Count () is used to count the number of occurrences of an element in the list
Str = ['output,' y','n','a','m', 'is',','m','y'] a = str.count ('m') b = str.count ('y') print (a) print (b)''output: 3 2 years'
Index () lookup, where an element first appears in the list
Str = ['output,' y','n','a','m', 'is',','m','y'] a = str.index ('m') b = str.index ('a') print (a) print (b)''output: 0 3''
The remove () function, which deletes the first match of a value in the list
Str = ['masked,' yearly, 'nasty,' axed, 'masked,' is', 'lumped,' masked,'y'] str.remove ('m`) str.remove ('is') print (str)' output: ['yearly,' nasty, 'ajar,' masked, 'lumped,' masked,'y']''
The sort () function, which sorts the elements in the list
Str = ['fags,' eBay, 'asides,' hacks, 'slots,' kills,'m'] str.sort () print (str) # output: ['asides,' eBay, 'fags,' hacks, 'kills,' masks,'s']
Copy () function, which can be used to copy a list
Str = ['fags,' eBay, 'asides,' hacks, 'slots,' kills,'m'] str.sort () string = str.copy () print (string) # output: ['asides,' eBay, 'fills,' hacks, 'kills,' masks,'s'] 4. Tuple tuple
Similar to lists, but tuples are generally unmodifiable
Tuple = ('lmy',' 2002, '9.15') print (tuple) print (tuple [0]) tuple = ('lmy',' 2002,'9,'15) print (tuple) 'output: (' lmy', '2002,' 9.15) lmy ('lmy',' 2002,'9,))''
Since the elements in the tuple cannot be modified, they can only be re-assigned, and the elements in the tuple cannot be deleted. We can only delete the whole tuple with del ().
5. Common functions of tuples
Len () function
Tuple = ('lmy',' 2002','9','15') a = len (tuple) print (a)''output:4'''
Max () and min () functions
Returns the largest and smallest elements in a tuple
Tuple = (152, 2002, 9, 15) a = max (tuple) b = min (tuple) print (a) print (b)''output:20029'''
The tuple () function, which converts a list to a tuple
List = [152,152,9,15] tuple = tuple (list) print (tuple)''output: (152,2002, 9,15)' 'the above is how to analyze the python list. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.