I want to add a loop to the end of another loop. But all I've tried failed and I don't know what to do
I've tried
for i in range(2):
print i
for r in range(4, 6):
print i.append(r)
and
for i in range(2):
print i
print i.append(4,5)
I expected:
0
1
4
5
But I received the following error instead:
Error for the 1st code sample:
Traceback:(most recent call last):
File "main.py", line 4, in <module>
print i.append(r)
AttributeError: 'int object has no attribute 'append'
Error for the 2nd code sample:
Traceback:(most recent call last):
File "main.py", line 4, in <module>
print i.append(4, 5)
AttributeError: 'int object has no attribute 'append'
range()gives you a list of integers, and iterating over that gives you each integer. Integers are not lists, so you can'tappendto them. What is it you're trying to accomplish?None, so nothing would print anyway.i = list(); for _ in range(2): for r in range(4, 6): i.append(r)i, then add another separate for loop forrand append r to i usingi.append(r)