The __post_init__ Hook

Medium Modern Python OOP Features
Solve in Playground →

Problem Statement

Create a `Rectangle` dataclass with `width` and `height`. Add an `area` attribute using `field(init=False)`. Use the `__post_init__` method to calculate and set the `area` as `width * height`. Print ‘Area: [area]’.

Input Format

Two space-separated integers.

Output Format

Print the calculated area.

Constraints

None

Sample Input

5 10

Sample Output

Area: 50

Explanation

The `__post_init__` hook is executed automatically right after the generated `__init__` method finishes, allowing complex initializations.

Starter Code

from dataclasses import dataclass, field

# Define Rectangle dataclass and __post_init__

if __name__ == '__main__':
    w, h = map(int, input().split())
    # Instantiate and print the area
    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