Professional Documents
Culture Documents
Python For Oil and Gas: Website - Linkedin - Youtube
Python For Oil and Gas: Website - Linkedin - Youtube
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
# syntax - ()
nums = (1, 2, 3)
/
2/2/2021 Python for O&G Lecture 41, 42: Tuples - Colaboratory
type(nums)
tuple
type(abc)
tuple
num1 = (1, )
type(num1)
tuple
num2 = ('Divyansh', )
type(num2)
tuple
# Now if we are't able to add or remove anything from tuples because they are immutable, why do we use them?
/
2/2/2021 Python for O&G Lecture 41, 42: Tuples - Colaboratory
# count method --> To count the no. of times a element is present in a tuple
tuple
phi.count(0.25)
# index method --> to know the index of any particular item in our tuple
phi.index(0.1)
# syntax - tuple_name.index(element, start arg, stop argument) # stop argument is not included
phi = (0.1, 0.25, 0.31, 0.1, 0.35, 0.25 ,0.1)
phi.index(0.1, 4)
6 /
2/2/2021 Python for O&G Lecture 41, 42: Tuples - Colaboratory
phi[6]
0.1
length function
# len(tuple_name)
num3 = (5, )
len(num3)
# same as of lists
phi = (0.1, 0.25, 0.31, 0.1, 0.35, 0.25 ,0.1)
phi[::-1]
phi[0] = 0.5
/
2/2/2021 Python for O&G Lecture 41, 42: Tuples - Colaboratory
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-21-d86134acf5ba> in <module>()
1 # let's try to update our tuple
2
----> 3 phi[0] = 0.5
for i in phi:
print(i)
0.1
0.25
0.31
0.1
0.35
0.25
0.1
# while loop
i = 0
while i < len(phi):
print(phi[i])
i = i+1
0.1
0.25
0.31
0.1
0.35
0.25
0.1
# type(tuple1)
type(tuple2)
tuple
Tuple unpacking
# Tuple unpacking
print(el3)
Python
/
2/2/2021 Python for O&G Lecture 41, 42: Tuples - Colaboratory
# This kind of unpacking can also be done in lists
a, b, c, d = abc
print(a)
print(d)
hey
5
# Now we can not add or remove anything in tuple but we can surely do it with lists
len(random)
random[3]
random[3].pop() /
2/2/2021 Python for O&G Lecture 41, 42: Tuples - Colaboratory
'Divyansh'
print(random)
random[3].append('hey')
print(random)
res_a = 0.2, 0.25, 0.55 # reservoir a's water sat, gas satur, hydrocarbon saturation
min(res_a)
0.2
max(res_a)
0.55
sum(res_a)
1.0
/
2/2/2021 Python for O&G Lecture 41, 42: Tuples - Colaboratory