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
Subtracting two numbers
Comparing two data values
Providing output to the user
Adding two numbers
seed()
sqrt()
factorial()
print()
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
What will be the output?
x = 10def fun(): global x x = 20fun()print(x)
10
20
Error
None
0
1
-1
2
Lists
Dictionary
String
All of the mentioned
def fun(a,b=5,c=10): print(a+b+c)fun(2,c=20)
27
17
22
def function function_name():
declare function function_name():
def function_name():
declare function_name():
none
lambda x => x+1
lambda(x): x+1
lambda x: x+1
def lambda(x): x+1
find the output of following code:
def add(a,b): return(a+b)print(add(3,4))
4
7
9
8
List
Tuple
Set
int
null
An exception is thrown without the return statement
Can contain multiple statements
Can have only one expression
Must use return statement
Cannot take arguments
Subroutines
Function
Definition
Modules
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
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)
6
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
One
Two
Three
Any Number of Times
What will be the output of the following Python code?
def foo(fname, val): print(fname(val))foo(max, [1, 2, 3])foo(min, [1, 2, 3])
3 1
1 3
error
none of the mentioned
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
#
&
*
**
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 code?
def s(n1): print(n1) n1=n1+2n2=4s(n2)print(n2)
6 4
4 6
4 4
6 6
break
pass
continue
none of these
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
bool
void
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)
strptime()
strftime()
Both A and B
None of the above
x='abcd'for i in x: print(i.upper())
a BCD
abcd
A B CD
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))
11
12
What will be the output of following?
Y=[2,5J,6]Y.sort()
[2,6,5J]
[5J,2,6]
[6,5J,2]
A built-in Python function
A one-line anonymous function
Lambda is a function in python but user can not use it.
What will be the output of the following Python function?
len(["hello",2, 4, 6])
3
Program gets into an infinite loop
Program runs once
Program runs n number of times where n is the argument given to the function
Arguments
Recursive Function
Lambda Function
Built-in Function
Generator Function
Calling one function from another function
Calling a function repeatedly from itself
Using nested loops
Using lambda functions
Heap
Stack
Uninitialized data segment
import mathprint(abs(math.sqrt(25)))
-5
5.0
def fun(a, b=5): print(a+b)fun(10, 20)
15
30
25
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
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
[0]
[1]
[1, 0]
[0, 1]
A static variable
A global variable
A local variable
An automatic variable
What is the output of the following code ?
def add(a, b): return a+5, b+5result = add(3,2)print(result)
(8,7)
def fun(a, b=6): a=a+b print(a)fun(5, 4)
User Defined Function
Library Functions
Builtin Functions
All of the above