Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
用于存储数据集的四种数据类型
List、Set、Dictionary、Tuple:
Type | Example | Features |
---|---|---|
Tuple | (1, 2, 3, 4) | ordered, unchangeable, allow duplicates |
List | [1, 2, 3, 4] | ordered, changeable, allow duplicates |
Set | {1, 2, 3, 4} | unordered, unchangeable, do not allow duplicates |
Dictionary | {“a”: 1, “b”: 2, “c”: “3”, “d”: “4”} | unordered, changeable, does not allow duplicates |
获取变量类型(type)
x = 5 s = "geeksforgeeks" y = [1,2,3] print(type(x)) # class 'int' print(type(s)) # class 'str' print(type(y)) # class 'list'
参考文献
Python Data Types
type and isinstance in Python – GeeksforGeeks
Python Sets / Python Lists / Python Dictionaries / Python Tuples