function_name()
call function_name()
ret function_name()
function function_name()
A static variable
A global variable
A local variable
An automatic variable
lambda x => x+1
lambda(x): x+1
lambda x: x+1
def lambda(x): x+1
Positional
Keyword
Default
Variable
What will be the output of the following Python code?
example = "helle" print(example.rfind("e"))
1
2
4
5
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
Increases code duplication
Reduces code reusability
Promotes code reusability and modularity
Makes program slower
List
Tuple
Dictionary
Set
extern
static
global
nonlocal
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
[0]
[1]
[1, 0]
[0, 1]
Subroutines
Function
Definition
Parameters
int
null
None
An exception is thrown without the return statement
What will be the output?
def fun(a, b=5): print(a+b)fun(10, 20)
15
30
25
Error
What is the output of following?
def test(): returnprint(test())
0
Blank
def foo(x): x = ['def', 'abc'] return id(x)q = ['abc', 'def']print(id(q) == foo(q))
True
False
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
procedure
function
bug
None of these
What is the value of the following Python code?
>>>print(36 / 4)
9
9.0
4.0
One
Two
Three
Any Number of Times
#
&
*
**
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
def foo(): return total + 1total = 0print(foo())
error
none of the mentioned
def function function_name():
declare function function_name():
def function_name():
declare function_name():
def f(a, b): print(a, b)f(b=2, a=1)
2 1
1 2
factorial()
print()
seed()
sqrt()
What is the output of the following code ?
def fun(a, b=6): a=a+b print(a)fun(5, 4)
11
def fun(a,b=5,c=10): print(a+b+c)fun(2,c=20)
27
17
22
none
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)
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
find the output of following code:
def add(a,b): return(a+b)print(add(3,4))
7
8
bool
void
x = 10def fun(): global x x = 20fun()print(x)
10
20
def disp(*arg): for i in arg: print(i)disp(name="Rajat", age="20")
TypeError
Rajat 20
Name age
def
fun
define
Declared outside all functions
Declared in loop
Declared using global
Declared inside a function
Global Scope
Built-in Scope
Local Scope
Module Scope
Can contain multiple statements
Can have only one expression
Must use return statement
Cannot take arguments
Arguments
def foo(): total += 1 return totaltotal = 0print(foo())
Local Variable
Static Variable
Global Variable
Instance Variable
What will be printed?
x = 10def f(): x = 20 print(x)f()print(x)
10 10
20 20
20 10
x = 5def f(): global x x = 10f()print(x)
def add(a, b=5): return a + bprint(add(3))
3
def fun(a,b=2,c=3): print(a,b,c)fun(1,c=10)
1 2 10
1 10 3
1 3 10
Define keyword in python
Define variable in python
Define function in python
All of the above
def foo(fname, val): print(fname(val))foo(max, [1, 2, 3])foo(min, [1, 2, 3])
3 1
1 3
x = 50def func (x): x = 2func (x)print ('x is now', x)
x is now 50
x is now 2
x is now 100