Default arguments function

Previous
Next

Argument Type Functions: Depends on the way of passing arguments(input values), functions are classified into

  • Default argument functions
    • Required argument functions
    • Keyword argument functions
    • Variable argument functions

Default arguments:

  • Assigning values to arguments while defining the function
  • When we don’t pass values, function executes with default values.
  • We can replace default values using parameter values also
def default(a=10,b=20,c=30):
    print("a val :",a)
    print("b val :",b)
    print("c val :",c)
    return

default()
default(20,"abc",34.56)

A Default argument can follows Non Default argument function

We can replace default argument values with same type of data and any other type of data as python is dynamic language.

def default(a,b,c=30):
    print("a val :",a)
    print("b val :",b)
    print("c val :",c)
    return
default(10,20)
default(50,100,150)

A Non default argument cannot follow default argument:

def default(a,b=20,c):
    print(a,b,c)
    return

default(10,30)

No value to “C” here, values applicable from left to right:

  • It is not allowed even we submit values to all arguments.
  • When we pass values to default arguments every time, then what is the use of default value
Previous
Next

Add Comment

Courses Enquiry Form