Expand class definiton examples
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
parent
7f2c84f53d
commit
011f10f9ae
|
@ -0,0 +1,2 @@
|
|||
__pycache__
|
||||
*.p[oc]
|
|
@ -0,0 +1,35 @@
|
|||
# employeeclass1.py
|
||||
|
||||
from personclass2 import Person
|
||||
|
||||
|
||||
class Employee(Person):
|
||||
|
||||
def __init__(self, name="", age=0, gender=None, employee_id=None, salary=0):
|
||||
super().__init__(name=name, age=age, gender=gender)
|
||||
self.employee_id = employee_id
|
||||
self.salary = salary
|
||||
|
||||
def __str__(self):
|
||||
return f"Employee: name={self.name} employee_id={self.employee_id}"
|
||||
|
||||
|
||||
employee1 = Employee()
|
||||
|
||||
print(employee1)
|
||||
print(employee1.__class__)
|
||||
print(employee1.name)
|
||||
print(employee1.age)
|
||||
print(employee1.gender)
|
||||
|
||||
employee2 = Employee("Joe Doe", 32, gender="m", employee_id=1, salary=2000)
|
||||
|
||||
print(employee2)
|
||||
print(employee2.__class__)
|
||||
print(employee2.name)
|
||||
print(employee2.age)
|
||||
print(employee2.gender)
|
||||
print(employee2.employee_id)
|
||||
print(employee2.salary)
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# personclass1.py
|
||||
# personclass2.py
|
||||
|
||||
class Person:
|
||||
|
||||
|
|
Loading…
Reference in New Issue