Recursive function can be replaced by a non-recursive function
Recursive functions usually take more memory space than non-recursive function
Recursive functions run faster than non-recursive function
Recursion makes programs easier to understand
#
&
*
**
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
8
6
9
What will be the output of the following Python code?
x='abcd'for i in x: print(i.upper())
a BCD
abcd
error
A B CD
(x**y)**z
(x**y) / z
(x**y) % z
(x**y)*z
None
0
Null
Arbitary value
def function function_name():
declare function function_name():
def function_name():
declare function_name():
fun
function
def
define
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
2
1
What will be the output of the following code snippet?
numbers = (4, 7, 19, 2, 89, 45, 72, 22)sorted_numbers = sorted(numbers)odd_numbers = [x for x in sorted_numbers if x% 2!=0]print(odd_numbers)
[7, 19, 45, 89]
[2, 4, 22, 72]
[4, 7, 19, 2, 89, 45, 72, 22]
[24, 7, 19, 22, 45, 72, 89]
What is the output of the following?
x=123for i in x: print(i)
1 2 3
123
Error
none of these
User Defined Function
Library Functions
Builtin Functions
All of the above
def foo(x): x = ['def', 'abc'] return id(x)q = ['abc', 'def']print(id(q) == foo(q))
True
False
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)
Subroutines
Function
Definition
Parameters
seed()
sqrt()
factorial()
print()
Recursive Function
Lambda Function
Built-in Function
Generator Function
Every recursive function must have a base case
Infinite recursion can occur if the base case isn’t properly mentioned
A recursive function makes the code easier to understand
Every recursive function must have a return value
A built-in Python function
A one-line anonymous function
Lambda is a function in python but user can not use it.
None of the above
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
An exception is thrown
A function that calls itself
A function that calls other functions
Both (A) and (B)
reverse(l)
list(reverse[(l)])
reversed(l)
list(reversed(l))
What will be the output?
def fun(a, b=5): print(a+b)fun(10, 20)
15
30
25
lambda x => x+1
lambda(x): x+1
lambda x: x+1
def lambda(x): x+1
The variables used inside function are called local variables.
The local variables of a particular function can be used inside other functions, but these cannot be used in global space.
The variables used outside function are called global variables.
In order to change the value of global variable inside function, keyword global is used.
What is the output of the following code ?
def add(a, b): return a+5, b+5result = add(3,2)print(result)
(8,7)
What is the output of the following
y='klmn'for i in range(len(y)): print(y)
klmn klmn klmn klmn
k
kkk
None of the these
Choose the correct function declaration of fun1() so that we can execute the following two function calls successfully.
fun1(25, 75, 55)fun1(10, 20)
def fun1(**kwargs)
def fun1(args*)
No, it is not possible in Python
def fun1(*data)
strptime()
strftime()
Both A and B
datetime
date
time
timedate
Global Scope
Built-in Scope
Local Scope
Module Scope
int
bool
void
What is the output of below program ?
def say(message, times =1): print(message * times)say("Hello")say("Word",5)
Hello WordWordWordWordWord
Hello Word 5
Hello Word,Word,Word,Word,Word
Hello HelloHelloHelloHelloHello
What will be the output of the following?
def iq(a,b): if(a==0): return b else: return iq(a-1,a+b)print(iq(3,6))
10
11
12
A function that calls other function.
A function which calls itself.
def foo(): total += 1 return totaltotal = 0print(foo())
none of the mentioned
In Module
In Class
In Another function
All of these
Modules
def foo(fname, val): print(fname(val))foo(max, [1, 2, 3])foo(min, [1, 2, 3])
3 1
1 3
x = 10def fun(): global x x = 20fun()print(x)
20
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))
null
An exception is thrown without the return statement
What is the output of this code?
def calc(x): r=2*x**2 return rprint(calc(5))
50
100
function_name()
call function_name()
ret function_name()
function function_name()
A function execution instance that calls another execution instance of the same function
A class method that calls another class method
An in-built method that is automatically called
Anonymous Function
Local Variable
Static Variable
Global Variable
Instance Variable