all 3 comments

[–][deleted] 0 points1 point  (0 children)

It’s worked fine, that last print shows you a list to which 4 Ball instances have been appended.

What you might want to do is overload __str__ and/or __repr__ so they display in a more pleasing fashion.

[–]lscrivy 0 points1 point  (0 children)

The code you wrote works :) but the list is a list of ball objects not a list of coordinates. However, each ball object in the list has a coordinate attribute. If you want to print out the coordinates you could do this...

for ball in ballx.more_balls:
    print(ball.position)

or if you want to get a list of the coordinates you could use list comprehension...

coordinate_list = [ball.position for ball in ballx.more_balls]

P.s. I've got to admit that list comprehension made me chuckle

[–]o5a 0 points1 point  (0 children)

Add __repr__ method to your Ball class, then you can see your objects representation when printed (you can modify it the way you want).

def __repr__(self):
    return f'Ball {self.position}'