Python For Og Lecture 76 and 77 - Oop Part 3
Python For Og Lecture 76 and 77 - Oop Part 3
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
l = [1, 2, 3, 4, 5]
l.pop()
print(l)
[1, 2, 3, 4]
l.append('oil')
print(l) /
2/3/2021 Python for O&G Lecture 76 and 77 : OOP - Part 3 - Colaboratory
[1, 2, 3, 4, 'oil']
# now we'll see how we can create our own such methods
class Reservoir:
self.porosity = por
self.permeability = perm
self.depth_of_reservoir = depth
# now I want to create a method for my class which describes the properties of reservoir in a nice manner
class Reservoir_2:
self.porosity = por
self.permeability = perm
self.depth_of_reservoir = depth
def describe(self):
return f'Porosity of this reservoir is {self.porosity*100}% and permiability is {self.permeability} md. This reservoir is located at the depth of {self.dep
/
2/3/2021 Python for O&G Lecture 76 and 77 : OOP - Part 3 - Colaboratory
res_a.describe()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-062bca49a4dc> in <module>()
----> 1 res_a.describe()
res_b.describe()
'Porosity of this reservoir is 41.0% and permiability is 50 md. This reservoir is located at the depth of 3200'
'Porosity of this reservoir is 20.0% and permiability is 89 md. This reservoir is located at the depth of 2500'
IMPORTANT POINT
# class_name.method_name(object_name)
Reservoir_2.describe(res_c)
'Porosity of this reservoir is 20.0% and permiability is 89 md. This reservoir is located at the depth of 2500'
/
a = [1, 2, 3, 4, 5]
2/3/2021 Python for O&G Lecture 76 and 77 : OOP - Part 3 - Colaboratory
a [1, 2, 3, 4, 5]
a.pop()
print(a)
[1, 2, 3, 4]
list.pop(a)
print(a)
[1, 2, 3]
print(a)
[1, 2, 3, 'oil']
Assignment 20
# create a method which calculates the averagae of all the subject's scores
# create another method which gives you max score out of three
/
class Scores:
2/3/2021 Python for O&G Lecture 76 and 77 : OOP - Part 3 - Colaboratory
class Scores:
def avg(self):
return (self.reservoir_score + self.drilling_score + self.production_score)/3
def maximum(self):
return max(self.reservoir_score , self.drilling_score , self.production_score)
Mohit.avg()
83.33333333333333
Shashank.avg()
74.0
Mohit.maximum()
90
Shashank.maximum()
96
/
2/3/2021 Python for O&G Lecture 76 and 77 : OOP - Part 3 - Colaboratory