python

[Python] Create a list of objects using class names

# In Python, the name of the class refers to the class instance. Consider:

class A: pass
class B: pass
class C: pass

lst = [A, B, C]

# instantiate second class
b_instance = lst[1]()
print(b_instance)
Was this helpful?