What is a data type
Simple understanding, containers for storing data
Data types are necessary attributes for each programming language. Only by assigning clear data types to data can computers process data. Therefore, it is necessary to use data types correctly. Data types are similar in different languages, but the specific expression methods vary
The following are commonly used data types for Python programming:
- Number (number)
- String (String)
- List
- Tuple
- Set
- Dictionary
Immutable data (3 pieces): Number, String, Tuple
variable data (3): List, Dictionary, Set
You can use the python built-in function type() function to view the data type
python
int_1 = 12
print(int_1, type(int_1))
float_1 = 12.33
print(float_1, type(float_1))
complex_1 = 2 + 7j
print(complex_1, type(complex_1))
bool_1=True
print(bool_1,type(bool_1))
str_1='fengfeng'
print(str_1,type(str_1))
list_1=[]
tuple_1=()
dict_1={}
set_1=set() #Creating empty collections is a bit special
print(list_1,type(list_1))
print(tuple_1,type(tuple_1))
print(dict_1,type(dict_1))
print(set_1,type(set_1))
12.33
(2+7j)
True
fengfeng
[]
()
{}
set()