Python Function :
- Function is a block of reusable code or program which can be called whenever required.
- python allows us to divide a large program into the basic blocks of code known as function.
- A function called multiple times.
- python provide us various inbuilt function like print() , range() etc.which can called user defined function.
- in python we can use def( ) keyword to define function.
Syntax :
def function_name():
statements....
return expression
Examples :
- A simple Function without parameters
>>> def hello_world():
print("Hello World")
>>> hello_world()
Hello World
>>>
- function with one parameter.
>>> a = 5
>>> def num(a):
print(a)
>>> num(a)
5
>>>
- function with two parameter
>>> def sum(a,b):
return a + b
>>> print(sum(10,20))
30
>>>
This comment has been removed by the author.
ReplyDelete