Memory Optimization with __slots__

Medium Modern Python OOP Features
Solve in Playground →

Problem Statement

Define a standard Python class `Point3D` that accepts `x`, `y`, and `z` in `__init__`. Use `__slots__ = (‘x’, ‘y’, ‘z’)` to restrict dynamic attributes. Catch an `AttributeError` if you try to assign `p.w = 4` and print ‘Slot restricted’.

Input Format

Three space-separated integers.

Output Format

Print 'Slot restricted'.

Constraints

None

Sample Input

1 2 3

Sample Output

Slot restricted

Explanation

Defining `__slots__` prevents the creation of `__dict__` for each instance, massively saving memory for objects instantiated frequently.

Starter Code

class Point3D:
    # Define __slots__ and __init__
    pass

if __name__ == '__main__':
    x, y, z = map(int, input().split())
    # Instantiate, attempt to assign .w, catch error
    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