>>> height = 70.0
>>> print("您的身高"+height)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
print("您的身高"+height)
TypeError: must be str, not float
| 函 数 | 作 用 |
|---|---|
| int(x) | 将 x 转换成整数类型 |
| float(x) | 将 x 转换成浮点数类型 |
| complex(real,[,imag]) | 创建一个复数 |
| str(x) | 将 x 转换为字符串 |
| repr(x) | 将 x 转换为表达式字符串 |
| eval(str) | 计算在字符串中的有效 Python 表达式,并返回一个对象 |
| chr(x) | 将整数 x 转换为一个字符 |
| ord(x) | 将一个字符 x 转换为它对应的整数值 |
| hex(x) | 将一个整数 x 转换为一个十六进制字符串 |
| oct(x) | 将一个整数 x 转换为一个八进制的字符串 |
>>> int("123") #转换成功
123
>>> int("123个") #转换失败
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
int("123个")
ValueError: invalid literal for int() with base 10: '123个'
>>>
版权说明:Copyright © 广州松河信息科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州松河信息科技有限公司 版权所有