Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k 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):

    my_objects.append(MyClass(i))

# 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.6k points)

Browse Categories

...