-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOPs.py
More file actions
87 lines (61 loc) · 2.09 KB
/
Copy pathOOPs.py
File metadata and controls
87 lines (61 loc) · 2.09 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# # Objective oriented Programming #
# # class is a blueprint of objects
# # object is an instance of a class
# class Employee:
# name = "harry"
# language = "python" #class attribute
# salary = 5000
# def __init__(self, name, language, salary): #dunder method which is automatically called
# print("I am creating an object")
# self.name = name
# self.language = language
# self.salary = salary
# # def getInfo(self):
# # print(f"the language is {self.language} and salary is {self.salary}")
# @staticmethod
# def greet():
# print("hello world")
# # harry = Employee()
# # harry.lastname = "singh" #instance attribute
# # print(harry.name, harry.language)
# # #instance attribute takes precedence over class attribute duing assignment and retrieval
# # Employee.getInfo(harry)
# # self is neccessary to provide in methods within class
# harry = Employee("harry", "javascript", 10000)
# harry.greet()
# print(harry.name, harry.language, harry.salary)
# class Programmer:
# company = "Microsoft"
# def __init__(self, name, salary, pin):
# self.name = name
# self.salary = salary
# self.pin = pin
# def getinfo(self):
# print(f"The name of the programmer is {self.name}, salary is {self.salary} and pin is {self.pin}")
# p = Programmer("anirban", 100000, 797979)
# # print(p.name, p.salary, p.pin, p.company)
# p.getinfo()
# class Calculator:
# def __init__(self, n):
# self.n = n
# @staticmethod
# def hello():
# print("Hello World!!")
# def square(self):
# print(f"The square is {self.n*self.n}")
# def cube(self):
# print(f"The cube is {self.n*self.n*self.n}")
# def squareRoot(self):
# print(f"The square root is {self.n**(1/2)}")
# a = Calculator(4)
# a.square()
# a.cube()
# a.squareRoot()
# a.hello()
# class Demo:
# a = 4 #class attribute
# o = Demo() # Prints the class attribute because instance attribute is not present
# print(o.a)
# o.a = 0 # Instance attribute is set
# print(o.a)
# print(Demo.a)