python 中的数据类型
python 在定义变量的时候不需要定义数据类型,导致很多小伙伴对python 中的数据类型不是很熟悉,通过这篇文章,我希望大家能够有所收获
python 中的数据类型,下面通过一段代码和结果展示给大家
print(type(100)) #整型 int
print(type(100.111)) # 浮点型 float
print(type(True)) #bool 类型 Ture 或者 False
print(type(4+1j)) # 复数 complex
print('------以上为数字类型---------')
print('%s --------字符串---------'% type('string')) #字符串 str
print('%s ------元组---------'% type(('张三','12'))) # 元组 tuple 小括号
print('%s ------列表---------'% type(['张三','12']))# 列表 list 中括号[]
print('%s ------字典---------'% type({'name':'张三','age':12})) # 字典 大括号{},以键值对的形式
print('%s ------set(集合)---------'% type({'Google', 'Taobao'})) # 集合 大括号的形式
可以查看代码对应的结果,分别如下所示
<class 'int'> #整型 int
<class 'float'> # 浮点型 float
<