What are Python containers? What is the role?

 

 

What are Python containers? What is the role? I believe that friends who have a certain understanding of Python containers should know that the commonly used containers of Python generally have four types: primitive ancestors, collections, dictionaries, and lists. In summary, the role of these Python containers is to store and manage a series of data in a unified manner. This article will take you one by one to analyze the specific content of the Python container. Friends who want to sort out the knowledge of the Python container can take a look together.

 

1. Tuple
  meta-ancestors are very similar to lists, but meta-ancestors cannot be modified once they are initialized, and they do not have append (), insert (), other methods for obtaining elements are the same as lists, and tupe [0 can be used normally. ], Tupe [-1], but cannot be assigned to another element. The role of Yuanzu is mainly reflected in the function can return multiple return values. 

 

2. Collection
  can store any type of data in the collection, there will be no duplicate data in the collection. Its basic functions include member detection and elimination of duplicate elements, and collection objects also support mathematical operations such as union, intersection, difference set, and symmetric difference. There are two common methods for adding Python collections, add and update. set1.add (data to be added) set1.update () deletes setl.remove (data to be deleted),, and removes an element from the collection setl.pop () 

 

3. Dictionary

  The dictionary is another variable container model, and can store any type of object. The role of the dictionary can be explained by the mapping relationship between things in many cases, such as the correspondence between the week and the number. As another example, sometimes we need a data structure such as a hash table to develop some efficient software. Each key-value key => value pair of the dictionary is separated by a colon: each key-value pair is separated by a comma, and the entire dictionary is enclosed in curly braces {}, the format is as follows: d = {key1: value1, key2: value2}. The dictionary value can take any Python object without limitation, either a standard object or a user-defined one, but the key does not work. It should be noted that the same key is not allowed to appear twice. If the same key is assigned twice during creation, the latter value will be remembered; the key must be immutable, so you can use numbers, strings, or tuples, so you ca n’t use a list. 

 

4. List
  is an ordered collection, and you can add and delete elements at any time. The role of the list can be summarized as unified management of multiple variables, storage and management of multiple data. Use the index to access each element in the list. Remember that the index starts at 0: When the index exceeds the range, Python will report an IndexError error. (classmates)-1. If you want to take the last element, in addition to calculating the index position, you can also use -1 as the index, and list [-1] directly gets the last element.

The above is the analysis of the types and specific functions of Python containers. Do you understand?

 

 

What are Python containers? What is the role? I believe that friends who have a certain understanding of Python containers should know that the commonly used containers of Python generally have four types: primitive ancestors, collections, dictionaries, and lists. In summary, the role of these Python containers is to store and manage a series of data in a unified manner. This article will take you one by one to analyze the specific content of the Python container. Friends who want to sort out the knowledge of the Python container can take a look together.

 

1. Tuple
  meta-ancestors are very similar to lists, but meta-ancestors cannot be modified once they are initialized, and they do not have append (), insert (), other methods for obtaining elements are the same as lists, and tupe [0 can be used normally. ], Tupe [-1], but cannot be assigned to another element. The role of Yuanzu is mainly reflected in the function can return multiple return values. 

 

2. Collection
  can store any type of data in the collection, there will be no duplicate data in the collection. Its basic functions include member detection and elimination of duplicate elements, and collection objects also support mathematical operations such as union, intersection, difference set, and symmetric difference. There are two common methods for adding Python collections, add and update. set1.add (data to be added) set1.update () deletes setl.remove (data to be deleted),, and removes an element from the collection setl.pop () 

 

3. Dictionary

  The dictionary is another variable container model, and can store any type of object. The role of the dictionary can be explained by the mapping relationship between things in many cases, such as the correspondence between the week and the number. As another example, sometimes we need a data structure such as a hash table to develop some efficient software. Each key-value key => value pair of the dictionary is separated by a colon: each key-value pair is separated by a comma, and the entire dictionary is enclosed in curly braces {}, the format is as follows: d = {key1: value1, key2: value2}. The dictionary value can take any Python object without limitation, either a standard object or a user-defined one, but the key does not work. It should be noted that the same key is not allowed to appear twice. If the same key is assigned twice during creation, the latter value will be remembered; the key must be immutable, so you can use numbers, strings, or tuples, so you ca n’t use a list. 

 

4. List
  is an ordered collection, and you can add and delete elements at any time. The role of the list can be summarized as unified management of multiple variables, storage and management of multiple data. Use the index to access each element in the list. Remember that the index starts at 0: When the index exceeds the range, Python will report an IndexError error. (classmates)-1. If you want to take the last element, in addition to calculating the index position, you can also use -1 as the index, and list [-1] directly gets the last element.

The above is the analysis of the types and specific functions of Python containers. Do you understand?

If you want to learn Python or are learning Python, there are a lot of Python tutorials, but is it the latest? Maybe you have learned something that people might have learned two years ago, and here I share a wave of the latest Python tutorials for 2020. How to get it, you can get it for free by editing the "Information" of the private letter!

 

Guess you like

Origin www.cnblogs.com/python0921/p/12754900.html