0 votes
1 view
in Python by (50.5k points)
How can I generate a list of objects (class instances) in Python?

1 Answer

0 votes
by (108k points)

You can store a list of object instances in the below manner in Python:

class MyClass(object):

    def __init__(self, number):

        self.number = number

my_objects = []

for i in range(100):


# later

for obj in my_objects:

    print obj.number

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jun 26, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !