Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.
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