python object list code example
Example 1: list class in python
class MyClass:
def __init__(self, signature):
self.signature = signature
def __repr__(self) -> str:
return str(self.signature)
class_list = []
for i in range(10):
class_list.append(MyClass(i))
print (class_list) # outputs [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Example 2: python list of objects
# Create a new class
class MyClass(object):
def __init__(self, number):
self.number = number
# Create a array to store your objects
my_objects = []
# Add 100 objects to array
for i in range(100):
my_objects.append(MyClass(i))