Keyword Arguments

Keyword Arguments


Keyword arguments will invoke the function after the parameters are recognized by their parameter names. The value of the keyword argument is matched with the parameter name and so, one can also put arguments in improper order (not in order).

Example:

def printdata (name):
print (“Example-1 Keyword arguments”)
print (“Name :”,name)
return
# Now you can call printdata() function
printdata(name = “Gshan”)

When the above code is executed, it produces the following output :

Output:

Example-1 Keyword arguments

Name :Gshan

Example:

def printdata (name):
print (“Example-2 Keyword arguments”)
print (“Name :”, name)
return
# Now you can call printdata() function
printdata (name1 = “Gshan”)

When the above code is executed, it produces the following result :

TypeError: printdata() got an unexpected keyword argument 'name1'

Example:

def printdata (name, age):
print ("Example-3 Keyword arguments")
print ("Name :",name)
print ("Age :",age)
return
# Now you can call printdata() function
printdata (age=25, name="Gshan")

When the above code is executed, it produces the following result:

Output:

Example-3 Keyword arguments

Name : Gshan

Age : 25

Qus. 1 : ____ are the arguments passed to a function in correct positional order.

  1. Required arguments
  2. Keyword arguments
  3. Default arguments
  4. Variable-length arguments

Programs

Python program to convert decimal into other number systems

View Solution


python program that generates six random numbers in a sequence created with start stop step

View Solution


Python program to illustrate the global variable

View Solution


python program to create a function to calculate factorial value

View Solution


Python program to find the sum of factorial upto n terms using function

View Solution


python program to create a function for reverse the number

View Solution


Python program to check number is Palindrome or not using function

View Solution


Python program to create a function for calculating sum of digit

View Solution


Python program to create recursive function to find factorial

View Solution


python function to accept 2 number and return addition subtraction multiplication and division

View Solution


python function to accept number of days and return week and days to its equivalent

View Solution


python function to extract the day month year from given date

View Solution


Python function to find the sum of all numbers between 100 and 500 which are divisible by 2

View Solution


Python function to get two matrices and multiply them

View Solution


python recursive function to find the sum of digits

View Solution


python recursive function to print the reverse of number

View Solution


Write a function with name dividebyfive which generate and prints a random integer number from the range 0 to 100 and then return True if the randomly generated number is divisible by 5, and False otherwise.

View Solution


Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad