Attributes of class
Variables that are defined at the class level are called attributes.
class Person:
name = 'Alex'
age = 10
name and age are class attributes.
Example:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
person = Person("John", 30)
setattr(person, "email", "john@example.com")
print(person.email) # john@example.com
name = getattr(person, "name")
print(name) # John
delattr(person, "age")
print(person.age)
Page of .
Leave a comment
You must be logged in to leave a comment.
Log in or
sign up to join the discussion.
Comments (0)