-
int 整型
-
float 浮点型
-
bool 布尔型
-
str 字符型 字符串
-
list 列表
-
tuple 元组
-
set 集合
-
dict 字典
-
查看数据类型使用的函数是 type()
# 数据类型查看的函数 type(数据/变量名)
# 基础数据类型:int float bool
# 容器类型: str list tuple set dict
# 整型
int1 = 12
print(type(int1)) # <class 'int'>
# 浮点型
float1 = 12.1
print(type(float1)) # <class 'float'>
# 布尔型 (True/False)
bool1 = True
print(type(bool1)) # <class 'bool'>
# 字符串型
str1 = 'hello Python'
print(type(str1)) # <class 'str'>
# 元组
tuple1 = (1, 2, 3, 4)
print(type(tuple1)) # <class 'tuple'>
# 列表
list1 = [1, 2, 3, 4]
print(type(list1)) # <class 'list'>
# 集合
set1 = {1, 2, 3, 4}
print(type(set1)) # <class 'set'>
# 字典
dict1 = {'name': 'xiaoming', 'age': 18} # <class 'dict'>
# 代码格式化的快捷键:ctrl + alt + L
# 练习:
a = 12
# a是什么数据类型? int
a = 'str'
# a是什么数据类型? str
a = '12'
# a是什么数据类型? str
a = True
# a是什么数据类型? bool
a = 13.4
# a是什么数据类型? float
# 通过上述演示,我们发现在Python程序执行过程中,可以随意改变变量的数据类型