0% found this document useful (0 votes)
11 views

Python For Og Lecture 64 - All Kind of Parameters Inside A Function

The document discusses different types of parameters that can be passed into a Python function including normal parameters, *args, default parameters, and **kwargs. It provides an example of a function that takes all these different parameter types and prints them out to demonstrate how each one works.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python For Og Lecture 64 - All Kind of Parameters Inside A Function

The document discusses different types of parameters that can be passed into a Python function including normal parameters, *args, default parameters, and **kwargs. It provides an example of a function that takes all these different parameter types and prints them out to demonstrate how each one works.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

2/2/2021 Python for O&G Lecture 64: All kind of parameters inside a function - Colaboratory

Python for Oil and Gas

Website - https://petroleumfromscratchin.wordpress.com/

LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch

YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw

# *args and **kwargs must be fresh in your minds at the moment


# let me tell you in short again about normal and default parameters

# normal parameter

def func(a):
return a+2

func(8)

10

def func 2(a, b=5): /


2/2/2021 Python for O&G Lecture 64: All kind of parameters inside a function - Colaboratory
_ ( , )
print(f'This function add the value of {b} to any given input')
return a + b

func_2(4)

This function add the value of 5 to any given input


9

Order of Parameters

# normal parameter, *args, default param, **kwargs -- MASTER ORDER

# create a function which takes porosity in normal parameters, formations names in *args
# depth as default parameters and info lik area name and field name in **kwargs
# this function prints all kind of parameters

def func_3(por, *args, depth = 3500, **kwargs):


print(por)
print(args)
print(depth)
print(kwargs)

func_3(0.16, 'Sandstone', 'shale', 'limestone', area = 'Assam', field = 'xyz')

0.16
('Sandstone', 'shale', 'limestone')
3500
{'area': 'Assam', 'field': 'xyz'}

func_3(0.16, 'Sandstone', 'shale', 'limestone', depth = 4000, area = 'Assam', field = 'xyz')

0.16
('Sandstone', 'shale', 'limestone')
4000
{'area': 'Assam', 'field': 'xyz'}

/
2/2/2021 Python for O&G Lecture 64: All kind of parameters inside a function - Colaboratory

You might also like