Concatenation of tuples

  • Normal text:

    • I'm having trouble coding in python 3.2.1. I actually take 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) 
  • when the program starts, the following error appears:

     divisors = divisors + (i) TypeError: can only concatenate tuple (not "int") to tuple 
+6
source share
2 answers

(1) not a tuple, its just an expression in brackets. To make it a tuple, add a trailing comma, (1,)

+26
source

Try using this instead:

 divisors.append(i) 

Edit:

 divisors = [] 

since you cannot add tuples.

-1
source

Source: https://habr.com/ru/post/895884/


All Articles