py的基础语法之数据类型

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

(1).整型

(2).浮点型

(3).布尔型

(4).字符串

(5).列表

(6).元组

(7).集合

(8).字典

 

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'> -- 字典

1. 为什么Python会提出这么多种的数据类型?

答:有限的内存, 无限的变量, 合理的使用内存

2.格式化输出

 

posted @ 2025-05-19 10:35  小猴子会上树  阅读(15)  评论(0)    收藏  举报