[Solved] Why is this simple 3 line program not working? [closed]


# First declare a class (empty, in this case)
class Pract:
    pass

# Then instantiate it
p1 = Pract()
# Then set the attribute
p1.age = 45
# Then print the attribute
print(p1.age)

You cannot instantiate a class before you finish declaring it. Everything you put inside class is part of the class definition. You have to de-indent your code in order to mark the end of the class definition.

1

solved Why is this simple 3 line program not working? [closed]