#
&
*
**
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
Positional
Keyword
Default
Variable
Global Scope
Built-in Scope
Local Scope
Module Scope
Arguments
Subroutines
Function
Definition
lambda x => x+1
lambda(x): x+1
lambda x: x+1
def lambda(x): x+1
What will be the output of the following Python code?
example = "helle" print(example.rfind("e"))
1
2
4
5
Required Argument
Keyword Argument
Default Argument
Decimal Argument
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
def foo(x): x = ['def', 'abc'] return id(x)q = ['abc', 'def']print(id(q) == foo(q))
True
False
None
Error
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 of the following Python function?
min(max(False,-3,-4), 2,7)
-3
-4
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)
User Defined Function
Library Functions
Builtin Functions
All of the above
What will be the output?
def fun(a,b=5,c=10): print(a+b+c)fun(2,c=20)
27
17
22
procedure
function
bug
None of these
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
[0]
[1]
[1, 0]
[0, 1]
def function function_name():
declare function function_name():
def function_name():
declare function_name():
Heap
Stack
Uninitialized data segment
int
null
An exception is thrown without the return statement
Local Variable
Static Variable
Global Variable
Instance Variable
What is the value of the following Python code?
>>>print(36 / 4)
9
9.0
4.0
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
datetime
date
time
timedate
strptime()
strftime()
Both A and B
One
Two
Three
Any Number of Times
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)
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
What is the output of the following code ?
def add(a, b): return a+5, b+5result = add(3,2)print(result)
15
(8,7)
Can contain multiple statements
Can have only one expression
Must use return statement
Cannot take arguments
def
fun
define
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
len(["hello",2, 4, 6])
3
6
def fun(a,b=2,c=3): print(a,b,c)fun(1,c=10)
1 2 10
1 10 3
1 3 10
A static variable
A global variable
A local variable
An automatic variable
What is the return type of following function ?
def func1(): return 'mnp',22print(type(func1()))
List
Dictionary
String
Tuple
Calling one function from another function
Calling a function repeatedly from itself
Using nested loops
Using lambda functions
A function that calls other function.
A function which calls itself.
Parameters
built-in functions
user-defined functions
py function
def disp(*arg): for i in arg: print(i)disp(name="Rajat", age="20")
TypeError
Rajat 20
Name age
Required arguments
Keyword arguments
Default arguments
Variable-length arguments
Segments
Modules
Units
All the above
def foo(): return total + 1total = 0print(foo())
0
error
none of the mentioned
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))
Define keyword in python
Define variable in python
Define function in python
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
In Module
In Class
In Another function
All of these
seed()
sqrt()
factorial()
print()
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.