Python TypeError: int() argument must be a string, a bytes原因

int()函数的TypeError

Python开发过程中,使用int()函数来转换或生成int类型的数据时,如果Python抛出并提示TypeError: int() argument must be a string, a bytes-like object or a real number, not 'complex',那么原因在于传递给int()函数的参数类型有误,正如TypeError的提示,int()函数的参数必须是string字符串(数值字符串)、类似字节对象、real number数字等,而不可以是complex复数类型的数据。

int()实例代码

python 复制代码
>>> str1 = '123'
>>> type(str1)
<class 'str'>
>>> int(str1)
123
>>> byteobj = b'56'
>>> type(byteobj)
<class 'bytes'>
>>> int(byteobj)
56
>>> realnumber = 3.12
>>> type(realnumber)
<class 'float'>
>>> int(realnumber)
3
>>> complexnum = 1+3j
>>> type(complexnum)
<class 'complex'>
>>> int(complexnum)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'complex'

原文:TypeError: int() argument must be a string, a bytes原因

免责声明:内容仅供参考!

相关推荐
薛定e的猫咪10 分钟前
【调试技巧】vscode 四种断点调试,快速定位 bug
ide·vscode·python·bug
CadeCode10 分钟前
Python 开发环境与包管理
python
b***748816 分钟前
PHP在电子商务系统中的构建
开发语言·php
爱写代码的小朋友25 分钟前
Python局域网远程监控电脑屏幕实现
python·flask·python监控电脑屏幕
岚天start26 分钟前
Java程序生成Heap Dump堆内存快照文件的多种方法
开发语言·python·pycharm
兆。29 分钟前
python全栈-人工智能基础-机器学习
人工智能·python·机器学习
天马行空-41 分钟前
ES 精准匹配 和 模糊查询的实现方式
java·开发语言
深度学习lover1 小时前
<项目代码>yolo遥感航拍船舶识别<目标检测>
人工智能·python·yolo·目标检测·计算机视觉·遥感船舶识别
Z***25801 小时前
Java计算机视觉
java·开发语言·计算机视觉
Tiger_shl1 小时前
SqlConnection、SqlCommand 和 SqlDataAdapter
开发语言·数据库·c#