Data Structure
Python has three built-in data structures: List, tuples, and dictionary.
1: List:
ListIs to process the data structure of a group of ordered projects, that is, you can store a series of projects in a list, in Python, you are separated by commas between each project
The items in the list should be included in square brackets so that python knows that you are specifying a list. For example, you can see that the list can contain strings or numbers. It can contain multiple types.
Related Function: Len (list) length list. append ('Rice ') after listing, add a string list. Sort () sorting list [0] to retrieve the first string.
The list is a variable data type:
For example:
Output:
This method affects the List itself, but the sort method does not return a modified list.
For example:
Output:
Note:You can addObjects of any typeIncluding number or other lists
2: tuples:The tuples are defined by commas (,) in parentheses. Tuples are usually used to securely use a group of values for statements or user-defined functions,That is, the value of the used tuples will not change..
For example:
Output:
Note:Tuples are the same as strings, that is, you cannot modify them.. For example, zoo [0] = "Others" also reports an error. The defined tuples cannot be changed.
3: Dictionary
Concept:Key(Name) andValueThe keys must be unique. Note that you can only use immutable objects (such as strings) as Dictionary keys.
Operation:
Add, delete, and modify, such:
Output:
Modify the value of DT:
Output:
Use dictionaryitemsTo read each key/value pair in the dictionary.
Output:
UseinOperator to check whether a key/value pair exists, or usedictClasshas_keyMethod.
Output:
Summary: items in the list and dictionary are variable. The values of tuples and strings are immutable.