TypeError: can only concatenate str (not “int“) to str

简介: TypeError: can only concatenate str (not “int“) to str

看见报的错误我们可以发现大致的错误。首先要做的是先梳理一下代码整体的思路,确保思路没有问题。然后再断点调试(每个步骤的打印也可以),这样可以很好的得到每个阶段所获得的值。定位错误,然后就是针对错误进行解决。

简而言之就是报错解决的范围太泛了(太大了),解决问题之前要做的就是先缩小问题的范围,精准打击image.png


**


我们可以发现报的错误是:
       TypeError:只能连接str(不是"int")到str

**


就是 + 只能链接字符串,不能连接int(整型)和字符串型,所以此时我们将int(整型)强制转换为字符串型,再通过加号连接起来就可以了image.png


所以只要强制转换个类型就可以了的


字符串:

字符串主要用于编程,概念说明、函数解释、用法详述见正文,这里补充一点:字符串在存储上类似字符数组,所以它每一位的单个元素都是可以提取的,如s=“abcdefghij”,则s[1]=“b”,s[9]=“j”,这可以给我们提供很多方便,如高精度运算时每一位都可以转化为数字存入数组。


整型:

计算机中的一个基本的专业术语,指没有小数部分的数据。整型可以用十进制,十六进制或八进制符号指定,前面可以加上可选的符号(- 或者 +)。包括整型常量和整型变量,整型变量又包括短整型、基本整型、长整型,它们都分为有符号和无符号两种版本,是一种智能的计算方式。


目录
相关文章
|
6月前
|
Python
TypeError: int() argument must be a string, a bytes原因
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复数类型的数据。
173 0
TypeError: randint() received an invalid combination of arguments - got (int, int, int), but expecte
TypeError: randint() received an invalid combination of arguments - got (int, int, int), but expecte
583 0
|
Python
Python类型转换的四个函数int()、float()、str()、bool()
Python类型转换的四个函数int()、float()、str()、bool()自制脑图 将一个类型的对象转换为其他对象类型转换不是改变对象本身的类型,而是根据当前对象的值创建一个新对象。
212 0
Python类型转换的四个函数int()、float()、str()、bool()
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
371 0
|
Python
【hacker的错误集】TypeError: can‘t multiply sequence by non-int of type ‘str‘
我比较喜欢通过单词的意思来分析报错 TypeError类型错误 multiply乘 sequence 序列 通过分析可以得出报错意思大概是类型错误:无法将序列与字符串类型的非整数相乘
329 0
【hacker的错误集】TypeError: can‘t multiply sequence by non-int of type ‘str‘
TypeError: sequence item 0: expected string, int found
TypeError: sequence item 0: expected string, int found
成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘
成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘
成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘
|
JSON 数据格式 Python
python编程:json indent can't multiply sequence by non-int of type 'str'
python编程:json indent can't multiply sequence by non-int of type 'str'
126 0
|
1月前
|
数据采集 分布式计算 数据处理
Dataphin常见问题之与指定类型int不兼容如何解决
Dataphin是阿里云提供的一站式数据处理服务,旨在帮助企业构建一体化的智能数据处理平台。Dataphin整合了数据建模、数据处理、数据开发、数据服务等多个功能,支持企业更高效地进行数据治理和分析。

热门文章

最新文章