Professional Documents
Culture Documents
Chapter (7) Function
Chapter (7) Function
Chapter (7) Function
Function
Function
A Function is a self-block of code. A Function can be called as a section of a program that is written
once and can be executed whenever required in the program, thus making code reusability.
Syntax:
Statements
def Intro():
print (“Hi!!!”)
Intro()
def Greeting(name):
Function Return
Return is used to return response to the caller function. Can use expression with the return
keyword.
def Getnum():
return num
def Sum(a,b):
return a+b
n2=int(Getnum())
n3=Sum(n1,n2)
PassingArgument Parameters
2) Default argument.
When the function call statement must match the number and order of arguments as defined in the
function definition it is Positional Argument matching.
def CentreInfo(name,phone):
CentreInfo("Pansodan",245180)
CentreInfo("Myaynigone",502233)
2) Default argument
Default Argument is the argument which provides the default values to the parameters passed in the
function definition, in case value is not provided in the function call.
def Contact(name,address="Yangon"):
print ""
Contact("Ma Htein")
Python Programming Ch 7-2
KMD Computer Centre
Contact("Mya Thandar","South Dagon")
When the function call give the arguments without limitation, need to accept with tupel object.*args
just means that the function takes a number of arguments, generally of the same type.
def Course(course,*syllabus):
Course("SE","SQL","C#","Java")
Course("PHP","HTML","CSS","JavaScript","JQuery","PHP","MySqL")
Lambda
Lambda function is used for creating small, one-time and anonymous function objects in Python.
Lambda operator can have any number of arguments, but it can have only one expression. It cannot
contain any statements and it returns a function object which can be assigned to any variable.
L=(lambda:(2+3))
print(L)#Location on CPU
print(L())
print("_______________________________________")
Multi=(lambda s,g:s*g)
Multi(5,4)