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
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)
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
int
null
None
An exception is thrown without the return statement
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
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?
def fun(a,b=5,c=10): print(a+b+c)fun(2,c=20)
27
17
22
Required Argument
Keyword Argument
Default Argument
Decimal Argument
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
def fun(a, b=6): a=a+b print(a)fun(5, 4)
11
5
4
What is the output of the following?
x=123for i in x: print(i)
1 2 3
123
none of these
Positional
Keyword
Default
Variable
2
1
0
none
Arguments
Subroutines
Function
Definition
Increases code duplication
Reduces code reusability
Promotes code reusability and modularity
Makes program slower
One
Two
Three
Any Number of Times
find the output of following code:
def add(a,b): return(a+b)print(add(3,4))
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
[0]
[1]
[1, 0]
[0, 1]
Heap
Stack
Uninitialized data segment
None of the above
procedure
function
bug
fun
def
define
def foo(): return total + 1total = 0print(foo())
none of the mentioned
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))
Local Variable
Static Variable
Global Variable
Instance Variable
Global Scope
Built-in Scope
Local Scope
Module Scope
def foo(fname, val): print(fname(val))foo(max, [1, 2, 3])foo(min, [1, 2, 3])
3 1
1 3
def foo(x): x = ['def', 'abc'] return id(x)q = ['abc', 'def']print(id(q) == foo(q))
True
False
example = "helle" print(example.rfind("e"))
def foo(): total += 1 return totaltotal = 0print(foo())
What is the value of the following Python code?
>>>print(36 / 4)
9.0
4.0
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
bool
void
What will be the output of following?
Y=[2,5J,6]Y.sort()
[2,6,5J]
[5J,2,6]
[6,5J,2]
Required arguments
Keyword arguments
Default arguments
Variable-length arguments
def s(n1): print(n1) n1=n1+2n2=4s(n2)print(n2)
6 4
4 6
4 4
6 6
break
pass
continue
lambda x => x+1
lambda(x): x+1
lambda x: x+1
def lambda(x): x+1
#
&
*
**
function_name()
call function_name()
ret function_name()
function function_name()
factorial()
print()
seed()
sqrt()
Null
Arbitary value
Can contain multiple statements
Can have only one expression
Must use return statement
Cannot take arguments
What is the return type of following function ?
def func1(): return 'mnp',22print(type(func1()))
List
Dictionary
String
Tuple
x = 10def fun(): global x x = 20fun()print(x)
10
20
Recursive Function
Lambda Function
Built-in Function
Generator Function
def fun(a,b=2,c=3): print(a,b,c)fun(1,c=10)
1 2 10
1 10 3
1 3 10
Set
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