Variable Shadowing (Instance vs. Class namespace)

Medium State Management (Variables)
Solve in Playground →

Problem Statement

Create a `Dog` class with a class variable `legs = 4`. Instantiate a dog and modify *only that instance’s* `legs` attribute to 3. Print the class variable and the instance variable on separate lines.

Input Format

None

Output Format

Print 'Class: [val]' on line 1, and 'Instance: [val]' on line 2.

Constraints

None

Sample Output

Class: 4
Instance: 3

Explanation

Assigning a value to an instance attribute with the same name as a class attribute 'shadows' the class variable for that specific instance, without changing the global class state.

Starter Code

class Dog:
    legs = 4

if __name__ == '__main__':
    # Instantiate a dog, shadow the legs variable, and print
    pass

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used