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

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

相关推荐
老王熬夜敲代码13 分钟前
C++中的atomic
开发语言·c++·笔记·面试
a努力。1 小时前
腾讯Java面试被问:String、StringBuffer、StringBuilder区别
java·开发语言·后端·面试·职场和发展·架构
长安第一美人1 小时前
php出现zend_mm_heap corrupted 或者Segment fault
开发语言·嵌入式硬件·php·zmq·工业应用开发
gihigo19981 小时前
基于MATLAB的电力系统经济调度实现
开发语言·matlab
飛6792 小时前
从 0 到 1 掌握 Flutter 状态管理:Provider 实战与原理剖析
开发语言·javascript·ecmascript
Data_agent2 小时前
学术爬虫实战:构建知网论文关键词共现网络的技术指南
python·算法
龚礼鹏2 小时前
Android应用程序 c/c++ 崩溃排查流程
c语言·开发语言·c++
Filotimo_2 小时前
在java开发中,什么是JSON格式
开发语言·json
咕噜签名-铁蛋2 小时前
云服务器远程连接失败?
开发语言·php
~无忧花开~2 小时前
Vue二级弹窗关闭错误解决指南
开发语言·前端·javascript·vue.js