Professional Documents
Culture Documents
Python For Og Lecture 63 - Kwargs Operator
Python For Og Lecture 63 - Kwargs Operator
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
def func(**kwargs):
return kwargs
dict
/
2/2/2021 Python for O&G Lecture 63: **kwargs operator - Colaboratory
func(1, 2, 3)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-e0aac76a4982> in <module>()
1 # just give positional argument here and see the results
2
----> 3 func(1, 2, 3)
# make a dictionary using **kwargs which takes porosity, permeability and depth as keys
def func_2(**kwargs):
return kwargs
Code Text
func_2(por = 0.15, perm = 35, depth = 3500)
def func_3(**abc):
for i, j in abc.items():
print(f'{i} is: {j}')
/
2/2/2021 Python for O&G Lecture 63: **kwargs operator - Colaboratory
165
465
{'por': 0.15, 'perm': 35, 'depth': 3500}
print(kwargs)
# In coming video, we will use *args, **kwargs, normal arguments all in one function and there we'll see the proper order of their positioning
/
2/2/2021 Python for O&G Lecture 63: **kwargs operator - Colaboratory
Dictionary Unpacking
dict_1 = {
'por' : 0.14,
'perm': '40 md',
'depth': '2500 ft'
}
def func_6(**kwargs):
return kwargs
func_6(**dict_1)
/
2/2/2021 Python for O&G Lecture 63: **kwargs operator - Colaboratory