Python For Og Lecture 78 - Oop Part 4
Python For Og Lecture 78 - Oop Part 4
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
Class Variable
class Circle:
self.pi = pi
self.radius = r
def area(self):
return self.pi*(self.radius)**2
def circum(self):
return 2*self.pi*self.radius
/
2/3/2021 Python for O&G Lecture 78: OOP Part 4 - Colaboratory
c_1 = Circle(3.14, 2)
c_2 = Circle(3.14, 3)
c_1.area()
12.56
c_2.circum()
18.84
# class variable is that variable inside class which have a common value for all the objects representing that particular class
class Circle_2:
self.radius = r
def area(self):
return Circle_2.pi*(self.radius)**2
def circum(self):
return 2*Circle_2.pi*self.radius
c_3 = Circle_2(2)
c_3.area()
/
2/3/2021 Python for O&G Lecture 78: OOP Part 4 - Colaboratory
12.56
c_4 = Circle_2(3)
c_4.circum()
18.84
# let's say we want to create a method which calculates pressure at given well depth
class Well:
mw = 12 # ppg
self.type_of_comp = comp_type
self.no_of_zones = zones
self.depth = depth
def pres_calc(self):
return 0.052*Well.mw*(self.depth)
well_1.pres_calc()
1560.0
well_1.__dict__