Default argument

Default Argument


In Python the default argument is an argument that takes a default value if no value is provided in the function call. The following example uses default arguments, that prints default salary when no argument is passed.

Example:

def printinfo( name, salary = 3500):
print (“Name: “, name)
print (“Salary: “, salary)
return
printinfo(“Mani”)

Output:

Name: Mani

Salary: 3500

When the above code is changed as print info(“Ram”,2000) it produces the following output:

Output:

Name: Ram

Salary: 2000

In the above code, the value 2000 is passed to the argument salary, the default value already assigned for salary is simply ignored.

Qus. 1 : <p>What is the output of below program ?</p><pre>def say(message, times =1):<br>&nbsp; &nbsp; print(message * times)<br>say("Hello")<br>say("Word",5)</pre>

  1. Hello WordWordWordWordWord
  2. Hello Word 5
  3. Hello Word,Word,Word,Word,Word
  4. Hello HelloHelloHelloHelloHello
Qus. 2 : How many arguments a Python program can accept from the command line?

  1. One
  2. Two
  3. Three
  4. Any Number of Times
Qus. 3 : <p>What is the output of the following code ?</p><pre>def fun(a, b=6):<br>&nbsp; &nbsp; a=a+b<br>&nbsp; &nbsp; print(a)<br>fun(5, 4)</pre><div><br></div>

  1. 11
  2. 9
  3. 5
  4. 4
Qus. 4 : <p>What is the output of the following code?</p><pre>def s(n1):<br>&nbsp; &nbsp; print(n1)<br>&nbsp; &nbsp; n1=n1+2<br>n2=4<br>s(n2)<br>print(n2)</pre><div><br></div>

  1. 6 4
  2. 4 6
  3. 4 4
  4. 6 6

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


CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad