欢迎来到测试Test-Admin的博客

本来以为,学习了这么多年,我已经洞察了世界,真相却不过是蒙蔽了自己。原来世界如此精彩,而我却一无所知。昨天已经成为过去,明天还是一个未知,但今天是一个礼物。珍惜自己,把握每一寸光阴!

python基础之---数据类型(三)

1、数据类型

在 Python 里为了应对不同的业务需求,也把数据分为不同的类型。

 

 检测数据类型的方法:type(变量名或者数值)

a = 1
print(type(a))  # <class 'int'> -- 整型

b = 1.1
print(type(b))  # <class 'float'> -- 浮点型

c = True
print(type(c))  # <class 'bool'> -- 布尔型

d = "12345"
print(type(d))  # <class 'str'> -- 字符串

e = [10, 20, 30]
print(type(e))  # <class 'list'> -- 列表

f = (10, 20, 30)
print(type(f))  # <class 'tuple'> -- 元组

h = {10, 20, 30}
print(type(h))  # <class 'set'> -- 集合

g = {"name": "张三", "age": 20}
print(type(g))  # <class 'dict'> -- 字典
  • Python是弱类型语言

  • 程序员不需要关心变量的类型, 只需要把数据书写正确即可,python会通过自动推到出您变量的类型。

posted on 2021-10-21 23:31  Test-Admin  阅读(62)  评论(0编辑  收藏  举报

导航