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

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

相关推荐
xfan_me1 分钟前
手机在网状态接口-空号查询-空号过滤API
数据库·人工智能·python·智能手机
HugoStudio_SWAN3 分钟前
【按键反馈】C++ 实现键盘烟花秀
开发语言·c++·学习·程序人生
测试秃头怪5 分钟前
Postman中变量的使用
自动化测试·软件测试·python·测试工具·测试用例·接口测试·postman
ynchyong5 分钟前
词云(Word Cloud) 使用方法
python·统计·词云
AI 编程助手GPT15 分钟前
Bun 1.4 正式发布:从 Zig 改写为 Rust,内置浏览器、图片处理和并行测试
开发语言·人工智能·后端·ai·chatgpt
Alkaid207716 分钟前
我把文件和脚本放一起了,Python 就是看不见?新手必看的绝对路径 vs 相对路径终极避坑指南
python·ai编程
paopaokaka_luck20 分钟前
基于springboot3+vue3的飞行器模型实验室预约管理系统(协同过滤算法、Echarts图形化分析)
开发语言·推荐算法
lingchen190624 分钟前
用MATLAB r2010b和r2016b求解微分方程组
开发语言·算法·matlab
ttwosix30 分钟前
JavaEE初阶 多线程 3
java·开发语言
SamChan9036 分钟前
Python+OpenCV检测PDF翻译后排版偏移:像素级格式一致性验证
python·opencv·ai·pdf·wpf