Python自动化--3.Python数据类型

python自动化更贴近运维自动化

Python自动化–1.Python环境安装-linux

Python自动化–2.Python变量

Python自动化–3.Python数据类型

Python自动化–4. python类型转换

Python自动化–5. if判断语句

Python自动化–6. 写一个python程序

Python自动化–7. 函数的定义和调用


3. Python数据类型

python的数据类型有:字符串、整型、列表、元组、字典、布尔型等等。数据类型是编程语言必备的属性,只有给数据赋予明确的数据类型,计算机才能对数据进行处理运算。

3.1 查看数据的类型,使用 type

In [1]: n = input("请输入一个数字>>:")
请输入一个数字>>:10

In [2]: n
Out[2]: '10'

In [3]: type(n)     #查看input接受到的数据类型
Out[3]: str

In [4]: type(10)
Out[4]: int

3.2 基本数据类型

整型

In [8]: type(9)
Out[8]: int

In [9]: type(0)
Out[9]: int

In [10]: type(-1)
Out[10]: int

浮点型

In [11]: type(1.3)
Out[11]: float

In [12]: type(0.5)
Out[12]: float

In [13]: type(-0.5)
Out[13]: float

布尔型

In [14]: type(True)
Out[14]: bool

In [15]: type(False)
Out[15]: bool

字符串

In [17]: type('False')
Out[17]: str

In [18]: type('F231dsdas')
Out[18]: str

In [19]: type('1900')
Out[19]: str

二进制

In [20]: type(b'hello')
Out[20]: bytes

In [21]: type(b'123')
Out[21]: bytes

如,想要把用户输入的 字符串(str) 和 整型(int) 进行大小比较,那么就需要进行数据类型转换 ,如字符串转换为整型

这个过程叫类型转换

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值