Viva Functions
Viva Functions
FUNCTIONS
VIVA QUESTIONS
1. What is a function?
Function is a named group of related programming statements which perform
a specific task. Functions are used to break the large code into smaller
manageable modules which are easy to manage and debug.
2. Need of functions
Some of the major advantages of using functions in a program are:
3. Types of functions
Basically, we can divide functions into the following three types:
• Built-in Functions
• Python Modules
• User-defined Functions
The keyword global may be used to access a global variable inside a function if
a local variable exists inside the function by the same name.
x=10 global x
print("x=",x) x=10
func() print("x=",x)
print(x) func()
print(x)
Program 1 Program 2
x= 10 x= 10
9 10
This is because in Python, variables that are only referenced inside a function
are implicitly global. If a variable is assigned a value or its value is modified
anywhere within the function’s body, it’s assumed to be a local unless explicitly
declared as global.
When arguments are passed as positional arguments, the order in which the
arguments are sent or their position is very important.
When arguments are passed as keyword arguments, the name of the argument
is given along with the value. In this case the position of arguments does not
matter. They can be written in random order.
2
Functions | Vineeta Garg