python – TypeError: 'int' object is not iterable" if you try to add a number to the list `end += int(i)`

Question:

x="234"
end=[]
for i in x:
    print i
    end+=int(i)#[1]
    print end
    end.reverse()
print end

[1]It also says that the iterator must not be an int. "TypeError: 'int' object is not iterable"

He brings out

2
3
4
['4', '2', '3']

Should it output 4,3,2

PS: the task itself that I want to test in python:
1) Any number X (set range)

2) mirror it (i.e. 123 = 321) minus X
a=(x.reverse()-x)

3) b=a+a.reverse()

As a result, according to the "focus" b should always = 1089

Answer:

+= on lists expects an entire collection, not a single element. Use .append() to add just one element:

>>> L = []
>>> L += 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> L.append(1)
>>> L
[1]
>>> L += [2, 3]
>>> L
[1, 2, 3]
Scroll to Top