总共7种数据类型:
3种基本数据类型:数值型、布尔型、字符串(str)
4种复合数据类型:列表(list)、元组(tuple)、集合(set)、字典(dict)
"""
python中一共7种数据类型
1.基本数据类型
数值:int、float
布尔:True、False
字符串:str
2.容器类型(数据序列)
列表 => list, [1, 2, 3] => 数据可以发生改变
元组 => tuple, (1, 2, 3) => 数据一旦定义,其值不能被改变
集合 => set, {1, 2, 3} => 自动去重
字典 => dict, {k:v键值对} => {'name':'张三', 'age':18} => 查询神器
"""
# 1.数值
# 整型
a = 10
print(type(a))
# 浮点型
b = 9.9
print(type(b))
print(25 * '-')
# 2.布尔
c = False
print(type(c))
print(25 * '-')
# 3.字符串
d = 'hello'
print(type(d))
# 扩展:可以通过isinstance函数判断一个变量是否为某种类型,返回True/False
print(isinstance(d, str))
print(isinstance(d, int))
print(isinstance(d, float))
print(isinstance(d, bool))
print(isinstance(d, list))
print(isinstance(d, set))
print(isinstance(d, tuple))
print(isinstance(d, dict))
print(25 * '-')
# 4.列表类型
e = [1, 2, 3, 4]
print(type(e))
print(e)
print(25 * '-')
# 5.元组类型
f = (1, 2, 3, 4)
print(type(f))
print(f)
print(25 * '-')
# 6.集合类型
g = {1, 1, 2, 5, 9}
print(type(g))
# 自动去重
print(g)
print(25 * '-')
# 7.字典类型
h = {
'name': '刘德华',
'age': 60,
'address': '香港九龙'
}
print(type(h))
print(h)