python数据类型

总共7种数据类型:
3种基本数据类型:数值型、布尔型、字符串(str)
4种复合数据类型:列表(list)、元组(tuple)、集合(set)、字典(dict)
python数据类型

"""
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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值