问题
Normal text:
- I'm having some problems with coding on python 3.2.1. Actually I'm taking online lectures that are on python 2.5.
Here is the code:
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)
is not a tuple, its just a parenthesized expression. To make it a tuple, add a trailing comma, (1,)
回答2:
Try to use this instead:
divisors.append(i)
Edit:
divisors = []
since you can't append on tuples.
来源:https://stackoverflow.com/questions/7192391/concatenation-of-tuples