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

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

相关推荐
sdgsdgdsgc16 小时前
Next.js企业级应用开发:SSR、ISR与性能监控方案
开发语言·前端·javascript
晓风残月淡17 小时前
JVM字节码与类的加载(二):类加载器
jvm·python·php
西柚小萌新19 小时前
【深入浅出PyTorch】--上采样+下采样
人工智能·pytorch·python
rit843249920 小时前
基于MATLAB的模糊图像复原
开发语言·matlab
fie888920 小时前
基于MATLAB的声呐图像特征提取与显示
开发语言·人工智能
_extraordinary_21 小时前
Java SpringMVC(二) --- 响应,综合性练习
java·开发语言
shut up21 小时前
LangChain - 如何使用阿里云百炼平台的Qwen-plus模型构建一个桌面文件查询AI助手 - 超详细
人工智能·python·langchain·智能体
宝贝儿好1 天前
【python】第五章:python-GUI编程
python·pyqt
@。1241 天前
对于灰度发布(金丝雀发布)的了解
开发语言·前端
闲人编程1 天前
从多个数据源(CSV, Excel, SQL)自动整合数据
python·mysql·数据分析·csv·存储·数据源·codecapsule