-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1.1Classes&Objects.py
More file actions
44 lines (27 loc) · 1.16 KB
/
1.1Classes&Objects.py
File metadata and controls
44 lines (27 loc) · 1.16 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
# --------------------
# SECTION - I - Classes and Objects
# --------------------
# position, name, age, level, salary
se1 = ["software engineer", "Max", 20, "Junior", 5000]
se2 = ["software engineer", "Lisa", 25, "Senior", 7000]
# class (blueprint of data structure)
class SoftwareEngineer:
# Class Attributes
alias = "Keyboard Magician"
# Special function to initialise our object (Constructor)
# Herein, self attribute will always be there
def __init__(self, name, age, level, salary):
# So the below mentioned attributes with a self keyword,
# are known as instance attributes and can be used inside the class.
# the attributes defined outside this function are called Class Attributes.
self.name = name
self.age = age
self.level = level
self.salary = salary
# Difference between Instance and Class Attributes:
# Instance Attributes belong to a specific object and not to the whole Class
# i.e., we can write: se1.alias, SoftwareEnginner.alias
# but not : SoftwareEngineer.name
# instance of class (object)
se1= SoftwareEngineer("Max", 20, "Junior", 5000)
print(se1.name, se1.age)