-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_1.py
More file actions
46 lines (34 loc) · 1.13 KB
/
tutorial_1.py
File metadata and controls
46 lines (34 loc) · 1.13 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Python Object Oriented Programming
class Employee(object):
def __init__(self, first, last, pay):
self.first = first
# self.fname = first
self.last = last
self.pay = pay
self.email = first + "." + last + "@company.com"
def fullname(self):
# The instance is always passed as an argument automatically
# to handle the argument always put self as the first argument
return "{} {}".format(self.first, self.last)
emp_1 = Employee("Test", "User", 50000)
emp_2 = Employee("Test2", "User2", 60000)
print(emp_1)
print(emp_2)
print()
# emp_1.first = "Test"
# emp_1.last = "User"
# emp_1.email = "Test.User@example.org"
# emp_1.pay = 50000
# emp_2.first = "Test2"
# emp_2.last = "User2"
# emp_2.email = "Test2.User2@example.org"
# emp_2.pay = 60000
print(emp_1.email)
print(emp_2.email)
print()
# print("{} {}".format(emp_1.first, emp_1.last))
# Invoking the method from the instance
# Employee.fullname(emp_1) - this happens in background
print(emp_1.fullname())
# Invoking the method using the class name directly and passing the instance as argument
print(Employee.fullname(emp_1))