I. Data type
There are six standard data types in Python:
- Number (numeric)
- String (String)
- List (lists)
- Tuple (tuple)
- Sets (collection)
- Dictionary (dictionary)
In addition to the list and dictionary dictionaries, the data types are immutable data types.
Two. Data structure
Common data structures in Python can be collectively referred to as Containers (container). sequences (such as lists and tuples), mappings (such as dictionaries), and collections (set) are the three main types of containers.
- List: Shoplist = [' Apple ', ' mango ', ' carrot ', ' banana ']
- Tuple: Tu = (123,456, ' hello ')
- Dictionary: di = {' A ': 123, ' B ': ' Something '}
- Collection: Fruitset = {' Apple ', ' pear ', ' apple '}
1. Lists and tuples
1 # 1. List with [], tuple with () 2 # 2. The contents of the list are variable, the tuple content is not mutable, but can be added in nested form 3 # 3. Nested lists within a tuple
4 # 4. Add "comma" when defining Ganso with only one element to avoid ambiguity with mathematical operations
5 # 5. Tuples typically have different data types, and lists are the same type of data queue. A tuple represents a struct, whereas a list represents a sequence
6 # 6. The list cannot be used as a dictionary key, and tuples can
Types and data structures in Python