I am trying to iterate through a list of string and make each element an instance of an object. I made a simplified version just to demonstrate my issue. When I run this code, I get an error saying that 'David' is not defined. I understand what I have done wrong: when I wrote 'People[i] = Person()', People[i] became the variable name instead of calling each element from the list.
How do I call each element on a list and make it a variable, so that in this case, when I print(David.name), it would print 'David'?
class Person:
def __init__(self):
self.name = "Unassigned"
People = ["David", "Emma", "Brian"]
for i in range(len(People)):
People[i] = Person()
print(David.name)