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

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

相关推荐
小白学大数据4 分钟前
AI 智能爬虫实战:Selenium+Python 自动绕反爬、一键提取数据
爬虫·python·selenium·数据分析
DreamLife☼5 分钟前
OpenBCI-实战二:脑波控制小游戏开发
python·pygame·openbci·cyton·ganglion
smj2302_796826526 分钟前
解决leetcode第3948题字典序最大的MEX数组
python·算法·leetcode
划水的code搬运工小李19 分钟前
下载CSDN到PDF
开发语言·pdf·swift
程序大视界21 分钟前
【Python系列课程】Pandas(六):数据读写——CSV与Excel文件操作
python·excel·pandas
不负岁月无痕23 分钟前
STL-- C++ stack_queue _priority_queue类 模拟实现
开发语言·c++
半个烧饼不加肉25 分钟前
JS 底层探究--上下文
开发语言·javascript·ecmascript
小满Autumn27 分钟前
依赖注入设计模式速查手册
开发语言·c#·wpf·mvvm·依赖注入
周末也要写八哥35 分钟前
浅谈:C++中cpp 14 ~ cpp 17
开发语言·c++·算法
不会C语言的男孩38 分钟前
C++ Primer 第13章:拷贝控制
开发语言·c++