Apr-19-2024, 10:56 AM
I don't understand classes in Python!
Why do I get a class like this, without declaring a class??
Employee
Why do I get a class like this, without declaring a class??
Employee = type("Employee", (object,), dict())Enter Employee in Idle:
Employee
Output:<class '__main__.Employee'>
Make an instance of Employee:employee = Employee() # Set salary to 1000 setattr(employee,"salary", 1000 ) # Get the Salary value = getattr(employee, "salary") print(value) # returns 1000 employee.salary # returns 1000