Home | | Problem Solving and Python Programming | Function definition(Sub program) - Python

Chapter: Problem Solving and Python Programming : Data, Expressions, Statements

Function definition(Sub program) - Python

def keyword is used to define a function.

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

 

Syntax:

def fun_name(Parameter1,Parameter2…Parameter n):

statement1

statement2…

statement n

return[expression]

 

Example:

def my_add(a,b):

c=a+b

return c

 

Function Calling: (Main Function)

 

Ø   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)

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Problem Solving and Python Programming : Data, Expressions, Statements : Function definition(Sub program) - Python |

Related Topics

Problem Solving and Python Programming : Data, Expressions, Statements


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.