We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2dc539b commit 2eb49e9Copy full SHA for 2eb49e9
1 file changed
Sprint5/generics.py
@@ -0,0 +1,21 @@
1
+from dataclasses import dataclass
2
+
3
+@dataclass(frozen=True)
4
+class Person:
5
+ name: str
6
+ age : int
7
+ children: list["Person"] #nside the Person class- the Person-type doesnt exist, so we add "" to person,
8
9
10
11
+Muhib = Person(name="Muhib",age= 7, children=[])
12
+Muiz = Person(name="Muiz",age= 4,children=[])
13
14
+Sara = Person(name="Sara",age= 31, children=[Muhib, Muiz])
15
16
+def print_family_tree(person: Person) -> None:
17
+ print(person.name)
18
+ for child in person.children:
19
+ print(f" {child.name} ({child.age})")
20
21
+print_family_tree(Sara)
0 commit comments