-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClassDemo.py
More file actions
33 lines (26 loc) · 882 Bytes
/
ClassDemo.py
File metadata and controls
33 lines (26 loc) · 882 Bytes
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
class MyFirstClass:
#class variable
machinetype = "computer"
def __init__(self,cpu,ram):
print("Inside __init__")
self.cpu = cpu
self.ramsize = ram
def HelloFromClass(self):
print("Nishit Dhakar is learning Class in Python")
print("Nishit Laptop is {} with {} ram".format(self.cpu,self.ramsize))
def compareClasses(self,other):
if self.cpu == other.cpu:
return True
else:
return False
a = MyFirstClass("i5","8Gb")
b = MyFirstClass("i7","16Gb")
MyFirstClass.machinetype = "ipad"
a.HelloFromClass()
if a.compareClasses(b) == True:
print("both are same", a.machinetype, b.machinetype)
else:
print("Both are different", a.machinetype, b.machinetype)
print(type(a))
#Alternate way to call method from a class
#MyFirstClass.HelloFromClass(a)