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
Can contain multiple statements
Can have only one expression
Must use return statement
Cannot take arguments
User Defined Function
Library Functions
Builtin Functions
All of the above
lambda x => x+1
lambda(x): x+1
lambda x: x+1
def lambda(x): x+1
strptime()
strftime()
Both A and B
None of the above
0
1
-1
2
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]
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
int
null
None
An exception is thrown without the return statement
Subroutines
Function
Definition
Modules
Increases code duplication
Reduces code reusability
Promotes code reusability and modularity
Makes program slower
A static variable
A global variable
A local variable
An automatic variable
Segments
Units
All the above
Define keyword in python
Define variable in python
Define function in python
What will be the output?
def fun(a, b=5): print(a+b)fun(10, 20)
15
30
25
Error
break
pass
continue
none of these
Global Scope
Built-in Scope
Local Scope
Module Scope
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
Local Variable
Static Variable
Global Variable
Instance Variable
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])
4
3
6
def foo(x): x = ['def', 'abc'] return id(x)q = ['abc', 'def']print(id(q) == foo(q))
True
False
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
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)
Heap
Stack
Uninitialized data segment
min(max(False,-3,-4), 2,7)
-3
-4
List
Tuple
Dictionary
Set
def fun(a,b=5,c=10): print(a+b+c)fun(2,c=20)
27
17
22
x = 10def fun(): global x x = 20fun()print(x)
10
20
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
procedure
function
bug
None of these
example = "helle" print(example.rfind("e"))
5
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
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
11
12
function_name()
call function_name()
ret function_name()
function function_name()
One
Two
Three
Any Number of Times
factorial()
print()
seed()
sqrt()
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
Recursive Function
Lambda Function
Built-in Function
Generator Function
fun
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))
8
In Module
In Class
In Another function
All of these
A function that calls other function.
A function which calls itself.
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 is the output of this code?
def calc(x): r=2*x**2 return rprint(calc(5))
50
100
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
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 value of the following Python code?
>>>print(36 / 4)
9.0
4.0