In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you what the built-in data structures in Python are, which are concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
List list
Features: there are several ways to manage data
Common methods
Add an element at the end of list.append (x)
Append a set of elements to the end of list.extend (x)
List.insert (iPermine x) inserts an element before subscript I
List.remove (x) deletes an element (if there are multiple identical elements, delete the first one)
Del list [I] deletes the element of subscript I
List.pop (I) pops up the element of subscript I (can be left empty, default to-1)
List.clear () empties the list
List [I] = n replace the elements of subscript I
List.index (n) finds the subscript of element n
List.count (n) finds the number of times element n appears in the list
List.sort () sorts the list in ascending order
Tuple tuple
Properties: data cannot be modified, so it is more efficient than lists
Common methods
Tuple.index (n) finds the subscript of element n in the list
Tuple.count (n) finds the number of times element n appears in the list
Special
The only way to change the tuple is to reassign it.
Dict dictionary
Properties: mapping type, storing data as a pair of key values, keys immutable
Because it is a mapping relationship, the value can only be found by key, so there is no index value.
Common methods
Dict [key] = value add / replace an element
Dict1.update (dict2) add / replace a set of elements
Dict.clear () empties the dictionary
Dict.pop (key) pops up the corresponding key element
Dict.get (key,default) returns the value of the corresponding key, otherwise it returns default. Default None
Special
Dict.keys () # returns the iterative object key
Dict.values () # returns the iterative object value
Dict.items () # returns a tuple of iterative object key values
Set collection
Properties: elements are not repetitive and out of order
Common methods
Set.add () add element
Set1.update (set2) add a new collection
Set.remove (n) deletes an element, if it does not exist, it will report a KeyError error
Set.discard (n) deletes an element, or pass if it does not exist
Set.clear () clears the collection
Special
Operations that can be done for multiple collections
S1-S2 difference set
S1 & S2 find the intersection
S1 | S2 merge set
S1 ^ S2 to find the symmetrical complement
Common method
Count the number of len ()
Max () to find the maximum
Min () to find the minimum
It is worth mentioning that strings can be divided into sizes in dictionary order.
What are the built-in data structures in Python? 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.