A function that calls itself
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
Segments
Modules
Units
All the above
What is the output of the following code?
x = 50def func (x): x = 2func (x)print ('x is now', x)
x is now 50
x is now 2
x is now 100
Error
Define keyword in python
Define variable in python
Define function in python
All of the above
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.
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
A function that calls other functions
Both (A) and (B)
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
What will be the output of the following Python function?
len(["hello",2, 4, 6])
4
3
6
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 is the return type of following function ?
def func1(): return 'mnp',22print(type(func1()))
List
Dictionary
String
Tuple
min(max(False,-3,-4), 2,7)
2
False
-3
-4
(x**y)**z
(x**y) / z
(x**y) % z
(x**y)*z
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
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
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]
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)
Lists
All of the mentioned
User Defined Function
Library Functions
Builtin Functions
A static variable
A global variable
A local variable
An automatic variable
A function that calls other function.
A function which calls itself.
Both A and B
def foo(x): x = ['def', 'abc'] return id(x)q = ['abc', 'def']print(id(q) == foo(q))
True
None
int
null
An exception is thrown without the return statement
1
0
none
Subroutines
Function
Definition
-1
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
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
x='abcd'for i in x: print(i.upper())
a BCD
abcd
error
A B CD
def foo(fname, val): print(fname(val))foo(max, [1, 2, 3])foo(min, [1, 2, 3])
3 1
1 3
none of the mentioned
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
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))
9
10
11
12
function_name()
call function_name()
ret function_name()
function function_name()
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
def add(a, b): return a+5, b+5result = add(3,2)print(result)
15
(8,7)
Making the code look clean
A complex task can be broken into sub-problems
Recursive calls take up less memory
Sequence generation is easier than a nested iteration
def fun(a, b=6): a=a+b print(a)fun(5, 4)
reverse(l)
list(reverse[(l)])
reversed(l)
list(reversed(l))
break
pass
continue
none of these
datetime
date
time
timedate
def function function_name():
declare function function_name():
def function_name():
declare function_name():
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
built-in functions
user-defined functions
py function
Heap
Stack
Uninitialized data segment
factorial()
print()
seed()
sqrt()
What is the output of this code?
def calc(x): r=2*x**2 return rprint(calc(5))
50
100
20
function
def
fun
define
def foo(): return total + 1total = 0print(foo())
;
: :
:
%