Python自动化--1.Python环境安装-linux Python自动化--2.Python变量 Python自动化--3.Python数据类型 Python自动化--4.python类型转换 Python自动化--5. if判断语句
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) 进行大小比较,那么就需要进行数据类型转换 ,如字符串转换为整型
这个过程叫类型转换