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

Default Parameters

The document discusses default parameters, keyword arguments, and positional arguments in functions. Default parameters define a default value if no argument is passed. Keyword arguments allow passing arguments in any order by name. Positional arguments must be passed in the defined order of the function parameters.

Uploaded by

lakemas535
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Default Parameters

The document discusses default parameters, keyword arguments, and positional arguments in functions. Default parameters define a default value if no argument is passed. Keyword arguments allow passing arguments in any order by name. Positional arguments must be passed in the defined order of the function parameters.

Uploaded by

lakemas535
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

default parameters:

def my_function(country = "Norway"):


print("I am from " + country)

my_function("Sweden")
my_function("India")
my_function()
my_function("Brazil")
output:
I am from Sweden
I am from India
I am from Norway
I am from Brazil
Keyword Arguments: Parameter Names are used to pass the argument during the
function call. Order of parameter Names can be changed to pass the argument(or values).
def nameAge(name, age):
print("Hi, I am", name)
print("My age is ", age)
nameAge(name="Prince", age=20)
nameAge(age=20, name="Prince")
Output
Hi, I am Prince
My age is 20
Hi, I am Prince
My age is 20
Positional Arguments: Arguments are passed in the order of parameters. The order
defined in the order function declaration. Order of values cannot be changed to avoid
the unexpected output.
During a function call, values passed through arguments should be in the order of parameters in the
function definition.

def nameAge(name, age):


print("Hi, I am", name)
print("My age is ", age)

# You will get correct output because argument is given in order


print("Case-1:")
nameAge("Prince", 20)
# You will get incorrect output because argument is not in order
print("\nCase-2:")
nameAge(20, "Prince")
Output
Case-1:
Hi, I am Prince
My age is 20

Case-2:
Hi, I am 20
My age is Prince

You might also like