Function definition: (Sub program)
v def keyword is used to define a function.
v Give the function name after def keyword followed by parentheses in which arguments are given.
v End with colon (:)
v Inside the function add the program statements to be executed
v End with or without return statement
def fun_name(Parameter1,Parameter2…Parameter n):
statement1
statement2…
statement n
return[expression]
def my_add(a,b):
c=a+b
return c
Ø Once we have defined a function, we can call it from another function, program or even the Python prompt.
Ø To call a function we simply type the function name with appropriate
arguments.
Example:
x=5
y=4
my_add(x,y)
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.