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

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

相关推荐
從南走到北8 分钟前
JAVA同城信息付费系统家政服务房屋租赁房屋买卖房屋装修信息发布平台小程序APP公众号源码
java·开发语言·小程序
月夜的风吹雨9 分钟前
【C++红黑树】:自平衡二叉搜索树的精妙实现
开发语言·c++·红黑树
TechMasterPlus19 分钟前
java:单例模式
java·开发语言·单例模式
程序员小远26 分钟前
如何搭建Appium环境?
自动化测试·软件测试·python·测试工具·职场和发展·appium·测试用例
烟袅32 分钟前
使用 OpenAI SDK 调用 Tools 实现外部工具集成
python·openai·agent
栗子~~43 分钟前
java-根据word模板灵活生成word文档-demo
java·开发语言·word
青瓷程序设计1 小时前
果蔬识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习
川石课堂软件测试1 小时前
自动化过程中验证码的解决思路
数据库·python·功能测试·测试工具·单元测试·tomcat·自动化
2301_764441331 小时前
新能源汽车电磁辐射高级预测
python·算法·数学建模·汽车
爱吃泡芙的小白白1 小时前
使用某云超算平台Jupyterlab的使用方法(自用)
运维·服务器·python·学习记录