Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Compare Class Attributes and Instance Attributes

Understand the difference between attributes defined on the class vs. the instance.

Python practice16 minClasses & Objects FundamentalsIntermediateLast updated April 7, 2026

Problem statement

You have a Car class with a class attribute wheels = 4. The constructor accepts an optional wheels argument; if provided it should set an instance attribute of that name. Implement is_using_class_attr(self) which returns True if the instance is using the class's wheels attribute (i.e., the instance does NOT have its own 'wheels' entry in its __dict__), and False if the instance has its own wheels attribute (even if its value equals the class value).

Task

Detect whether an instance is using the class attribute (inherited) or has its own instance attribute.

Examples

Default car uses class attribute

Input

Car().is_using_class_attr()

Output

True

No instance attribute was set, so wheels comes from the class.

Input format

Construct a Car optionally with an integer wheels parameter: Car() or Car(3).

Output format

A boolean: True if the instance is using the class attribute (no own attribute), False otherwise.

Constraints

Do not modify class-level state in the constructor. Detection should rely on presence of the attribute in the instance dictionary.

Samples

Sample 1

Input

Car(4).is_using_class_attr()

Output

False

Passing 4 to the constructor creates an instance attribute, so the instance is not using the class attribute even though values match.