Python Tutorials · Python Class Properties

Python Class Properties

Learn all about Python Class Properties in this comprehensive tutorial.

5 min read advanced
  • Properties are variables that belong to a class.
  • You can access object properties using dot notation:
  • You can modify the value of properties on objects:
  • You can delete properties from objects using the del keyword:
  • Properties defined inside __init__() belong to each object (instance properties).
  • When you modify a class property, it affects all objects:
  • You can add new properties to existing objects:

Class Properties

Properties are variables that belong to a class. They store data for each object created from the class.

python

Access Properties

You can access object properties using dot notation:

python

Modify Properties

You can modify the value of properties on objects:

python

Delete Properties

You can delete properties from objects using the del keyword:

python

Class Properties vs Object Properties

Properties defined inside __init__() belong to each object (instance properties).

Properties defined outside methods belong to the class itself (class properties) and are shared by all objects:

python

Modifying Class Properties

When you modify a class property, it affects all objects:

python

Add New Properties

You can add new properties to existing objects:

python
Note: Note: Adding properties this way only adds them to that specific object, not to all objects of the class.

Module quiz

2 questions
1

Which of the following is true about Python Class Properties?

2

What is the most common pitfall when working with Python Class Properties?

Answer all questions to submit.