class attribute

An attribute defined in the class body, shared by every instance of the class.

A shared mutable class attribute silently leaks data between instances.

In more detail

It suits values common to all instances, such as a species name. A mutable class attribute, such as a list, is shared too, so appending to it from one instance changes it for all, the shared mutable attribute trap; create per-instance lists in __init__ instead.

Related terms

Taught in

References

Certification courses