Can contain multiple statements
Can have only one expression
Must use return statement
Cannot take arguments
def function function_name():
declare function function_name():
def function_name():
declare function_name():
What will be the output of the following python program?
def addItem(listParam): listParam+=[1]mylist=[1,2,3,4]addItem(mylist)print(len(mylist))
5
8
2
1
What will be the output of the following Python code?
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
[0]
[1]
[1, 0]
[0, 1]
def fun (a = 2, b = 3, c)
def fun(a = 2, b, c = 3)
def fun(a, b = 2, c = 3)
def fun(a, b, c = 3, d)
A static variable
A global variable
A local variable
An automatic variable
What will be the output?
def fun(a,b=2,c=3): print(a,b,c)fun(1,c=10)
1 2 10
1 10 3
1 3 10
Error
What is the output of the following code ?
def disp(*arg): for i in arg: print(i)disp(name="Rajat", age="20")
TypeError
Rajat 20
Name age
None of these
In Module
In Class
In Another function
All of these
0
none
def foo(): total += 1 return totaltotal = 0print(foo())
error
none of the mentioned
datetime
date
time
timedate
from math import factorialprint(math.factorial(5))
120
Nothing is printed
NameError: name 'math' is not defined
Error, the statement should be print factorial(5))
factorial()
print()
seed()
sqrt()
What is the output of the following code?
def s(n1): print(n1) n1=n1+2n2=4s(n2)print(n2)
6 4
4 6
4 4
6 6
A function that calls itself
A function that calls other functions
Both (A) and (B)
None of the above
What will be the output of following?
Y=[2,5J,6]Y.sort()
[2,6,5J]
[5J,2,6]
[6,5J,2]
def fun(a,b=5,c=10): print(a+b+c)fun(2,c=20)
27
17
22
int
null
None
An exception is thrown without the return statement
Required arguments
Keyword arguments
Default arguments
Variable-length arguments
-1
fun
function
def
define
What is the value of the following Python code?
>>>print(36 / 4)
9
4
9.0
4.0
What will be the output of the following Python expression?
print(round(4.5676,2))
4.5
4.6
4.57
4.56
A function that calls other function.
A function which calls itself.
Both A and B
def fun(a, b=6): a=a+b print(a)fun(5, 4)
11
List
Tuple
Dictionary
Set
#
&
*
**
break
pass
continue
none of these
Heap
Stack
Uninitialized data segment
Program gets into an infinite loop
Program runs once
Program runs n number of times where n is the argument given to the function
An exception is thrown
Subtracting two numbers
Comparing two data values
Providing output to the user
Adding two numbers
Arguments
Subroutines
Function
Definition
User Defined Function
Library Functions
Builtin Functions
All of the above
Modules
Repeating a process in a loop
Calling a function from within itself
Using a loop to iterate over elements
Breaking down a problem into smaller subproblems
x = 50def func (x): x = 2func (x)print ('x is now', x)
x is now 50
x is now 2
x is now 100
It’s easier to code some real-world problems using recursion than non-recursive equivalent
Recursive functions are easy to debug
Recursive calls take up a lot of memory
Programs using recursion take longer time than their non-recursive equivalent
def foo(fname, val): print(fname(val))foo(max, [1, 2, 3])foo(min, [1, 2, 3])
3 1
1 3
What will be the output of the following Python code ?
def display(b,n): while n>0: print(b,end='') n=n-1display('z',3)
zzz
zz
Infinite loop
How many numbers will be printed by the following code?
def fun(a,b): for x in range(a,b+1): if x%3==0: print(x,end=" ")fun(100,120)
7
6
def fun(a, b=5): print(a+b)fun(10, 20)
15
30
25
Required Argument
Keyword Argument
Default Argument
Decimal Argument
Local Variable
Static Variable
Global Variable
Instance Variable
procedure
bug
function_name()
call function_name()
ret function_name()
function function_name()
What will be the output of the following Python function?
import mathprint(abs(math.sqrt(25)))
-5
5.0
x='abcd'for i in x: print(i.upper())
a BCD
abcd
A B CD
Calling one function from another function
Calling a function repeatedly from itself
Using nested loops
Using lambda functions