Python For Og Lecture 73 74 75 - Oop Part 1 and 2
Python For Og Lecture 73 74 75 - Oop Part 1 and 2
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
# concept of OOP is in many popular languages. But syntax differsin each language
# It does not increase any functionality. OOP is just a style of writing easy and managable code.
# class and object(instance), method --> three words you'll hear more now
# example
/
2/3/2021 Python for O&G Lecture 73, 74, 75: OOP - Part 1 and 2 - Colaboratory
list_1 = []
# all above are different objects but all belong to same class i.e. list
# example: Cricket match is a class. Test match, ODI and T20 matches are objects of my class Cricket
# method
flow_rate.append(450)
print(flow_rate)
list_1.append('Divyansh')
print(list_1)
['Divyansh']
list_1.append('Sethi')
print(list_1)
['Divyansh', 'Sethi']
# So, strings tuples dictionaries and lists all these are already created classes. We have been working already with OOP
/
# I hope you get the idea behind OOP. If not don't worry, as we proeceed you'll get better at it
2/3/2021 Python for O&G Lecture 73, 74, 75: OOP - Part 1 and 2 - Colaboratory
# I hope you get the idea behind OOP. If not don t worry, as we proeceed you ll get better at it
# STEP 1
# You always use class keyword and then name of class with first letter capital
# STEP 2
# then define a special method -> init method or constructor. SYNTAX - __init__(self, attr1, attr2, .....)
# self is the representation of the object
# STEP 3
# self.instance_variable1 = attr1
# self.instance_variable2 = attr2
# self.instance_variable3 = attr3
class Reservoir:
self.porosity = por
self.permeability = perm
self.depth_of_reservoir = depth
/
2/3/2021 Python for O&G Lecture 73, 74, 75: OOP - Part 1 and 2 - Colaboratory
# objects
this works
res_a.porosity
0.14
res_c.depth_of_reservoir
3655
# whenever we call the class, first thing happens in __init__ method (constructor) get called
# (to prove this we can add any statement just after the __init__ method)
# self represents our object. MEANS __init__ takes always first input of self. So our object name doesn't matter here
# self.porosity means object.porosity which will give the porosity of our object
# self represents object1 and also object 2 and all other objects as well
# You can use any other term as well in place of self. But prefereed is self
Assignment 19
/
2/3/2021 Python for O&G Lecture 73, 74, 75: OOP - Part 1 and 2 - Colaboratory
# create a class 'Well' with attributes like completion type, no. of zones, depth of well
class Well:
def __init__(self, comp_type, zones, depth):
self.type_of_comp = comp_type
self.zones = zones
self.depth = depth
well_1.type_of_comp
'cased well'
well_1.depth
2500
well_2.zones
/
2/3/2021 Python for O&G Lecture 73, 74, 75: OOP - Part 1 and 2 - Colaboratory