Professional Documents
Culture Documents
Chapter 3 - Type A - Short Answer Based Questions
Chapter 3 - Type A - Short Answer Based Questions
2. What all information does a function header give you about the function?
Explanation
A function header is the first line of a function definition. It begins with the def
keyword and ends with a colon ":". In the function header, there will be a function
name and its parameters. Parameters are the variables that are listed within the
parenthesis of a function header
1
3. What do you understand about the flow of execution?
Answer - The flow of execution refers to the order in which statements are
executed during a program run.
4. What is the utility of: - (i) Default arguments (ii) Keyword arguments?
Answer
(i)A parameter having a default value in function header becomes optional in
function call. Functions call may or may not have value for it.
(ii)Keyword arguments are the named arguments with assigned values being
passed in the function call statement.
5. What are arguments? What are parameters? How these two terms are
different yet related? Give example.
Answer
Parameter: - A name used inside a function to refer to the value which was passed
to it as an argument.
For example: -
def addEm(x, y, z) :
print(x + y + z)
addEm(6, 16, 26)
• In the above code, arguments are 6, 16 and 26; and parameter are x, y and z.
Answer
2
7. Explain with a code example the usage of default arguments and keyword
arguments.
Answer
Keyword argument can be used in any order and fir the argument skipped, there is a
default value.
Answer - Parts of program within which a name is legal and accessible, is called
scope of the name. The scope resolving rule of Python is LEGB rule.
Answer –
1. Built-in functions: - These are pre-defined functions and are always available for
use.
For example: - len(), type(), int(), input() etc.
2. Functions defined in modules: - These functions are pre-defined in particular
modules and can only be used when the corresponding module is imported.
For example:- If you to use pre-defined functions inside a module, say sin(), you
need to first import the module math (that contains definition of sin() ) in your
program.
3. User defined functions: - These are defined by the programmer. As programmers
you can create your own functions.
3
10. What is the difference between local and global variables?
Answer
Local variable:-
Global variable: -
For example: -
t = squared (2,3,4)
print(t)
Output is:-
(4, 9, 16)
12. When is global statement used? Why is its use not recommended?
Answer
Use:-
The global statement is a declaration which hold for the entire current code block. It
means that the listed identifiers are part of the global namespace or global
environment.
4
13. Write the term suitable for following description:
(a) A name inside the parentheses of a function header that can receive a
value.
(b) An argument passed to a specific parameter using the parameter name.
(c) A value passed to a function parameter.
(d) A value assigned to a parameter name in the function header.
(e) A value assigned to a parameter name in the function call.
(f) A name defined outside all function definitions.
(g) A variable created inside a function body.
Answer
(a) Parameter.
(b) Keyword argument.
(c) Argument.
(d) Default argument.
(e) Keyword argument.
(f) Global variable.
(g) Local variable.
14. What do you understand by local and global scope of variables? How
can you access a global variable inside the function, if function has a
variable with same name?
Answer :-
Global scope :-
A global variable is a variable defined in the ‘main’ program. Such variables are said
to have global scope.
For example : -
def s():
t = 15
print (t)
t = 95
print (t)
s()
print (t)