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
What will be the output of the following Python code?
def foo(): total += 1 return totaltotal = 0print(foo())
0
1
error
none of the mentioned
x='abcd'for i in x: print(i.upper())
a BCD
abcd
A B CD
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
Required arguments
Keyword arguments
Default arguments
Variable-length arguments
def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))
50
100
74
Infinite loop
A static variable
A global variable
A local variable
An automatic variable
Heap
Stack
Uninitialized data segment
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)
What will be the output of the following Python function?
len(["hello",2, 4, 6])
4
3
Error
6
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
def function function_name():
declare function function_name():
def function_name():
declare function_name():
What is the return type of following function ?
def func1(): return 'mnp',22print(type(func1()))
List
Dictionary
String
Tuple
What will be the output of the following Python expression?
print(round(4.5676,2))
4.5
4.6
4.57
4.56
def a(n): if n == 0: return 0 elif n == 1: return 1 else: return a(n-1)+a(n-2) for i in range(0,4): print(a(i),end=" ")
0 1 2 3
An exception is thrown
0 1 1 2 3
0 1 1 2
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
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
One
Two
Three
Any Number of Times
l=[] def convert(b): if(b==0): return l dig=b%2 l.append(dig) convert(b//2) convert(6) l.reverse() for i in l: print(i,end="")
011
110
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)
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(x): x = ['def', 'abc'] return id(x)q = ['abc', 'def']print(id(q) == foo(q))
True
False
None
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
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 is the output of this code?
def calc(x): r=2*x**2 return rprint(calc(5))
20
Define keyword in python
Define variable in python
Define function in python
All of the above
min(max(False,-3,-4), 2,7)
2
-3
-4
Subtracting two numbers
Comparing two data values
Providing output to the user
Adding two numbers
def foo(): return total + 1total = 0print(foo())
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 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]
User Defined Function
Library Functions
Builtin Functions
int
null
An exception is thrown without the return statement
break
pass
continue
none of these
def s(n1): print(n1) n1=n1+2n2=4s(n2)print(n2)
6 4
4 6
4 4
6 6
sum(2,4,6)sum([1,2,3])
Error, 6
12, Error
12, 6
Error, Error
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))
function
def
fun
define
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
A recursive function that has two base cases
A function where the recursive functions leads to an infinite loop
A recursive function where the function doesn’t return anything and just prints the values
A function where the recursive call is the last thing executed by the function
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
built-in functions
user-defined functions
py function
What is the value of the following Python code?
>>>print(36 / 4)
9.0
4.0
Lists
All of the mentioned
Null
Arbitary value
factorial()
print()
seed()
sqrt()
def add(a, b): return a+5, b+5result = add(3,2)print(result)
15
8
(8,7)
datetime
date
time
timedate
strptime()
strftime()
Both A and B
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
[0]
[1]
[1, 0]
[0, 1]