We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f3fe73 commit 2363068Copy full SHA for 2363068
class-methods.py
@@ -0,0 +1,26 @@
1
+from datetime import date
2
+
3
+class Employee:
4
+ def __init__(self,name,age):
5
+ self.age=age
6
+ self.name=name
7
8
9
+ def displayInfo(self):
10
+ return f"Name {self.name} age {self.age}"
11
12
+ @classmethod
13
+ def fromBirthYear(cls,name,birth_year):
14
+ return cls(name=name,age=(date.today().year-birth_year))
15
16
17
+emp1=Employee(name="Jonathan",age=23)
18
+emp2=Employee.fromBirthYear(name="Jerry",birth_year=1985)
19
20
21
+print(emp1.displayInfo())
22
+print(emp2.displayInfo())
23
24
25
26
0 commit comments