Professional Documents
Culture Documents
Q 2.Define and Explain Local and Global Variable with suitable Example.
g=10
def show( ):
l=20
global g
print("Local Variable= ",l)
print("Global Variable= ",g)
show()
#local variable l=20
#Global variable g=10
Q 3.Write a short note on Function with default Argument.
->As we know that Function is nothing but block of code that is execute by
calling it.
->Python supports default argument in Function,A Default argument that
assumes a default value if value is not passed into Function.
Example:
def disp(name,age=18)
print(“Name: ”,name)
print(“Age: ”,age)
return
disp(name=”Vivek”)
o/p:
Name:Vivek
Age:18
->In Python, Modules are simply files with the “.py” extension containing
Python code that can be imported inside another Python Program.
->In simple terms, we can consider a module to be the same as a code library
or a file that contains a set of functions, classes ,list etc that you want to
include in your application.
Writing/Creating Modules
->It means simply creating a file which can contains python definitions and
statements. The file name is the module name with the extension “.py”.To
include module in a file, we use import statement.
Steps:
1)Create a first File as a python program with extension as “.py”.This will be
your module file where we can write functions which perform some task.
2)Now create second file in the same directory called as main file where we
can import the module to the top of the file and call the function.
->As we know that Function is nothing but block of code that perform some
action and once defined it can be reused.
->we can also pass the parameters to this Function at the time of calling,this
passed parameter are nothing but actual parameter.
Actual Parameter:
->That means Actual values that are passed to Function,it in form of either
values or variables.
Formal Parameter