Normal text:
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
Method #1 : Using + operator This is the most Pythonic and recommended method to perform this particular task. In this, we add two tuples and return the concatenated tuple. No previous tuple is changed in this process.
Tuple AdditionYou can combine tuples to form a new tuple. The addition operation simply performs a concatenation with tuples. You can only add or combine same data types.
Use the list() function(converts the sequence/iterable to a list) to convert both the input tuples into a list. Use the extend() function(adds all the elements of an iterable like list, tuple, string etc to the end of the list) to append or concatenate the above 2nd list to the first list.
(1)
is not a tuple, its just a parenthesized expression. To make it a tuple, add a trailing comma, (1,)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With