Commit ffc50f6
committed
Add dataclasses-exercise.py: Person class using @DataClass decorator
- Create Person class with @DataClass(frozen=True) decorator
- Use datetime.date for date_of_birth instead of int for age
- Replace manual __init__ with declarative field definitions
- Implement is_adult() method with dynamic age calculation
- Account for whether birthday has occurred this year
- Add type hints for all attributes and methods
- Include example usage with imran and eliza instances
- Demonstrate immutable dataclass with frozen=True1 parent 4876f0d commit ffc50f6
1 file changed
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
0 commit comments