User Defined Function

Function parameters


Parameters are the value(s) provided in the parenthesis when we write function header. These are the values required by function to work. Let‟s understand this with the help of function written for calculating area of circle.

radius is a parameter to function area.

If there is more than one value required by the function to work on, then, all of them will be listed in parameter list separated by comma.

Arguments are the value(s) provided in function call/invoke statement. List of arguments should be supplied in same way as parameters are listed. Bounding of parameters to arguments is done 1:1, and so there should be same number and type of arguments as mentioned in parameter list.

Example

of argument in function call

>>> area (5)

5 is an argument. An argument can be constant, variable, or expression.

Qus. 1 : <p>What will be the output of the following Python code?</p><pre>def unpack(a,b,c,d):<br>&nbsp; &nbsp; print(a+d)<br>x = [1,2,3,4]<br>unpack(*x)</pre>

  1. Error
  2. [1,4]
  3. [5]
  4. 5
Qus. 2 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">def foo(k):&nbsp; &nbsp; &nbsp;&nbsp;<br></span><span style="font-size: 14px; white-space: normal;"><span style="white-space:pre"> </span>k[0] = 1&nbsp;&nbsp;<br></span><span style="font-size: 14px;">q = [0]&nbsp;&nbsp;<br></span><span style="font-size: 14px;">foo(q)&nbsp;&nbsp;<br></span><span style="font-size: 14px;">print(q)</span></pre>

  1. [0]
  2. [1]
  3. [1, 0]
  4. [0, 1]
Qus. 3 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">def foo(fname, val):<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print(fname(val))<br></span><span style="font-size: 14px;">foo(max, [1, 2, 3])<br></span><span style="font-size: 14px;">foo(min, [1, 2, 3])</span></pre>

  1. 3 1
  2. 1 3
  3. error
  4. none of the mentioned
Qus. 4 : <p>How many numbers will be printed by the following code?</p><pre>def fun(a,b):<br>&nbsp; &nbsp; for x in range(a,b+1):<br>&nbsp; &nbsp; &nbsp; &nbsp; if x%3==0:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(x,end=" ")<br>fun(100,120)</pre>

  1. 7
  2. 8
  3. 6
  4. 9
Qus. 5 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 12.6px;">example = "helle" print(example.rfind("e"))</span><br></pre>

  1. 1
  2. 2
  3. 4
  4. 5
Qus. 6 : <p>What is the output of the following</p><pre style="font-size: 12.6px; letter-spacing: 0.14px;">y='klmn'<br>for i in range(len(y)):<br>&nbsp; &nbsp; print(y)</pre>

  1. klmn klmn klmn klmn
  2. k
  3. kkk
  4. None of the these
Qus. 7 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">x='abcd'<br></span><span style="font-size: 14px;">for i in x:<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print(i.upper())</span></pre><div><br></div><p><br></p>

  1. a BCD
  2. abcd
  3. error
  4. A B CD
Qus. 8 : A statement is used when a statement is required syntactically but you do not want any code to execute.

  1. break
  2. pass
  3. continue
  4. none of these
Qus. 9 : What is a variable defined outside a function referred to as ?

  1. A static variable
  2. A global variable
  3. A local variable
  4. An automatic variable
Qus. 10 : what is Lambda function in python

  1. A built-in Python function
  2. A one-line anonymous function
  3. Lambda is a function in python but user can not use it.
  4. None of the above
Qus. 11 : Which of the following function headers is correct ?

  1. def fun (a = 2, b = 3, c)
  2. def fun(a = 2, b, c = 3)
  3. def fun(a, b = 2, c = 3)
  4. def fun(a, b, c = 3, d)
Qus. 12 : Which one of the following is the correct way of calling a function?

  1. function_name()
  2. call function_name()
  3. ret function_name()
  4. function function_name()
Qus. 13 : <p>find the output of following code:</p><pre><span style="font-size: 14px;">def add(a,b):<br></span><span style="font-size: 14px;">&nbsp; &nbsp; return(a+b)<br></span><span style="font-size: 14px;">print(add(3,4))</span></pre>

  1. 4
  2. 7
  3. 9
  4. 8
Qus. 14 : ____ keyword used for function in python

  1. fun
  2. function
  3. def
  4. define
Qus. 15 : def keyword use for?

  1. Define keyword in python
  2. Define variable in python
  3. Define function in python
  4. All of the above
Qus. 16 : Which keyword is used for function in Python language?

  1. function
  2. def
  3. fun
  4. define

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