本文介绍了元组的串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
普通文本:
Normal text:
- 我在使用 python 3.2.1 进行编码时遇到了一些问题.实际上,我正在参加有关 Python 2.5 的在线讲座.
代码如下:
x = 100
divisors = ()
for i in range(1,x):
if x%i == 0:
divisors = divisors + (i)
在运行程序时,出现以下错误:
on running the program, following error appears:
divisors = divisors + (i)
TypeError: can only concatenate tuple (not "int") to tuple
推荐答案
(1)
不是元组,它只是一个带括号的表达式.要使其成为元组,请添加尾随逗号 (1,)
(1)
is not a tuple, its just a parenthesized expression. To make it a tuple, add a trailing comma, (1,)
这篇关于元组的串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!