Ch2a Study Material
Ch2a Study Material
CHAPTER-2 : FUNCTIONS
WEIGHTAGE: 10 Marks
SYLLABUS OF FUNCTIONS CHAPTER
● Types of function (built-in functions, functions defined in module,
user defined functions),
● flow of execution,
Function header
Function body
Ans:
a. Function refers to a set of codes (or) statements which perform a particular task.
Ans:
stmt1 → stmt6 —> stmt2,3,4,5 —->stmt7—> stmt2,3,4,5→stmt8
4. Difference between Default and Positional parameters.
Ans:
Default parameters are those parameters for which the values are already assigned.
Positional parameters are those parameters for which the inputs to be passed in correct order.
5. Can a function return three values.
Ans:
Yes.
Ans:
Yes.
Ans:
Option c
We know the rule that: “default parameters should be at the last in parameter list”
8. What is the output of the following program?
def say(message, times = 1):
print(message * times , end ='')
say(‘Hello and’)
say('World', 5)
Options:
(a) Hello and WorldWorldWorldWorldWorld
(b) Hello and World 5
(c) Hello and World,World,World,World,World
(d) Hello and HelloHelloHelloHelloHello
Ans:
Option (a) Hello and WorldWorldWorldWorldWorld
9. Identify the valid program out of the following 2 programs:
#Program -1 #Program -2
helloPython() def helloPython():
def helloPython(): print("I love Programming")
print("I love Programming") helloPython()
helloPython() helloPython()
Ans:
Program-2 is valid
In Program-1, function defintion is present after the function call statement. So it is invalid.
Rule: In Python programming, function definition should be present before all the function call
statements
10. The following question is Assertion-Reasoning based, answer the
questions by choosing one of the following responses:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
Assertion(A) : A function can have either zero or any number of parameters
Reasoning(R) :Parenthesis are not mandatory to call a function with zero parameters
Ans:
(c) A is true but R is false
11. The following question is Assertion-Reasoning based, answer the
questions by choosing one of the following responses:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
Assertion(A) : Number of parameters passed to a function may not match the
number of parameters in the function definition.
Ans:
(a) Both A and R are true and R is the correct explanation of A.
12. Define Scope of a variable.
Ans:
def f1(N=10):
N*=20
print(N)
f1()
print(N) —--------It is error. N is created inside f1(). So it is a local variable. It can’t be accessed
outside f1()
Scope of a variable:
The part of a program where a variable is accessible is referred as Scope of a variable.
13. Difference between global and local variable.
Ans:
Global variable Local variable
The variables which are created outside a function are The variables which are created inside a function are
referred as Global variables referred as Local variables
Global variables can be accessed throughout the Local variables can be accessed and modified only
program but inorder to modify it inside a function, within the function.
global declaration is mandatory.
Ans:
built-in functions module functions user-defined functions
The functions which are already The functions which are already The functions which are developed
developed and available in the developed and stored in a by the users are referred as user-
python library are referred as built- particular python file are referred defined functions
in functions as module functions
➔ Function definition (i.e function) should be placed before the function call statement(s)
➔ Global variables : can be accessed throughout the program but inorder to modify it inside a
function, global declaration is mandatory.
➔ Local variables : can be accessed and modified only within the function.
➔ return statement makes the control to come from out a function and then it returns the specified
value(s) to the calling statement.