Default arguments follows non-default

Опубликовано: 11 Апрель 2026
на канале: Mastering Technology
77
19

Default arguments follows non-default
Default arguments always come after Non-Default Arguments

Understand the difference Between Parameters and Arguments
   • Difference Between Parameters & Arguments ...  

Default Arguments- These are the values provided while defining the function. If the user does not provide the value during calling of the function, it automatically fetches the default one.

def cube(l=10,b=5,h=10): #function definition
return l*b*h

Default arguments always follow non-default

def cube(l, b=5,h=10):
return l*b*h

print(cube(7)) #output : 7*5*10=350
print(cube(7,6)) #output: 7*6*10=420

Note: You can also provide all new values during calling of the function

print(cube(5,6,5)) #output : 5*6*5=150

Invalid Case:

def cube(l=10,b,h):
return l*b*h

It throws an error

In the following, default follows non-default but the default value is already present, so it also causes an error.

def cube(l=10,b,h=9):
return l*b*h

It also throws an error

#pythonprogramming #function #definition #parameters #placeholder #values #default #arguments #non #default #arguments #calling #function #change #default #values #return #statement #difference #between #parameters #arguments #error
#like #share #subscribe