Class Attributes


  • Class attributes can be created inside a class.
  • Assign to class attribute and fetch from it.
  • Class attributes can be also created from the outside.
  • Creating a instance does not impact the class attribute.


examples/oop/person1.py

class Person:
    name = 'Joseph'

print(Person.name)    # Joseph

Person.name = 'Joe'
print(Person.name)    # Joe

Person.email = 'joe@foobar.com'
print(Person.email)   # joe@foobar.com

x = Person()
print(Person.name)    # Joe
print(Person.email)   # joe@foobar.com