0

python multiple append

tile = [] recta = pygame.Rect(0, 0, 100, 100) recto = pygame.Rect(0 100, 100, 100) tile.append(recta, recto) so it says, appends takes exactly one argument, so what other way is there to append multiple variables besides doing tile.append(--) in multiple lines or should i just define it all in the set to begin with..

23rd Aug 2021, 2:18 PM
Tomoe
Tomoe - avatar
3 Answers
+ 3
Tomoe , => please give us an example how list tile should look like when recta and recto are "added" to the list. is it a nested data structure ? => what data type does recta and recto have? here some samples that may help you: lst = [1,2,3] lst += [4,5,6] lst += (0,0,10,30) print(lst) #result is: [1, 2, 3, 4, 5, 6, 0, 0, 10, 30] lst.append([9,8,7]) print(lst) # result: [1, 2, 3, 4, 5, 6, 0, 0, 10, 30, [9, 8, 7]] lst1 = [] a = [1,2,3] b = [4,5,6] lst1.append(a) lst1.append(b) print(lst1) # result is: [[1, 2, 3], [4, 5, 6]]
23rd Aug 2021, 2:38 PM
Lothar
Lothar - avatar
+ 2
https://pytutorial.com/JUMP_LINK__&&__python__&&__JUMP_LINK-append-multiple-list BTW you could have easily found this information yourself.
23rd Aug 2021, 2:33 PM
Simon Sauter
Simon Sauter - avatar
+ 1
How many rectangles do you have in total? If you have many, you would use a loop anyways, don't you? If it's only the 2 you can append them individually?
23rd Aug 2021, 2:36 PM
Lisa
Lisa - avatar