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原因

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

相关推荐
Java后端的Ai之路24 分钟前
Anthropic 官方文章《Building always-on agents》构建指南
开发语言·网络·python
船神丿男人38 分钟前
从爬楼梯到最小路径和:6 道 C++ 动态规划题的状态设计
开发语言·c++·动态规划
Evand J39 分钟前
【MATLAB例程】基于多基站AOA与距离辅助的二维运动目标定位及速度估计,附下载链接
开发语言·matlab·距离·aoa·多基站
数字供应链安全产品选型43 分钟前
从自动化扫描到 AI 自主攻防:下一代渗透测试需要突破哪些核心技术?
开发语言·php
badhope1 小时前
Agent 说发布成功,文章却 404:我补了 4 张回读收据
后端·python·ai编程
xurileidian1 小时前
第 30 篇 · 边玩边学Python · 猜数字小游戏 把判断循环异常串起来
前端·python·算法
赤生云电竞1 小时前
云电竞GPU虚拟化选型:vGPU与直通架构实践对比
java·开发语言·架构
吹什么轩2 小时前
c++高并发内存池(一):从objectpool到central cache
java·开发语言
leeshuqing2 小时前
剪刀石头布-Python练习
python·游戏·优化·列表·字典·控制语句
ZhuoAIStage2 小时前
图上有设备,机房条件0命中:剧院舞台音视频提资缺项,AI智能体为何判「需补充」不判「设计错漏」
python·正则表达式·舞台工艺·智能体审图·提资核查