[go: up one dir, main page]

0% found this document useful (0 votes)
49 views11 pages

FUNCTIONS

Uploaded by

harshalnarim2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views11 pages

FUNCTIONS

Uploaded by

harshalnarim2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

NAME: HARSHAL GAJANAN NARIM

STD: SYBSCIT
DIV: B
ROLL No: 111
SUBJECT: PYTHON PROGRAMMING
COLLEGE: M.L.DAHANUKAR COLLEGE OF COMMERCE
FUNCTIONS
IN
PYTHON
FUNCTIONS

 Function is a group of related statements that


performs a specific task.
 A Function is a block of program statements which
can be used repetitively in a program.
 It saves the time of a developer.
 In python concept of function is same as in other
language.
RULES FOR DEFINING FUNCTION IN PYTHON

 Functions block begin with the keyword def followed


by the function name, parentheses (). This line is
known as the function header.
 The function header must end with a colon.
 Parameters are defined inside parentheses.
 Parameters are local to the function.
FUNCTION SYNTAX

Input parameter is
The keyword placed within the
def parenthesis() and also
introduces a define parameter inside
function the parameter
definition
def
functionname(parameters):
“function_docstring”
function suite
return[expression]
The code block
within every
Return statement exits a
function starts
function block. And we can
with a colon(:).
also use return with no
argument
CALL A FUNCTION IN PYTHON

 Calling a function in Python is similar to other


programming languages, using the function name,
parenthesis (opening and closing) and arguments(s)
 SYNTAX:
function_name(arg1,arg2)
Code:

Eg:
def f1():
print(“Hello World”)
def f2(n=“ABC”):
print(“Hello”,n) Function Defination
def f3(n1,n2):
s=n1+n2
return s
f1()
name=input(“\n Enter your name:”)
f2(name)
f2() Function Call
print(“\n Enter 2 numbers:”)
x,y = input().split()
sum=f3(int(x),int(y))
print(“Sum=”,sum)
Math Function

 To use mathematical functions, you have to import the math module


using
import math
 Functions in Python Math Module
ceil(x) = Returns the smallest integer greater than or equal to
x.
factorial(x) = Returns the factorial x.
pow(x,y) = Returns x raised to the power y.
sqrt (x) = Returns the square root of x
e = mathematical constant
ADVANTAGES OF FUNCTIONS

 Functions group multiple statements into a block,


making the program easier to read and debug.
 When a block of statements in grouped into a
function, it eliminates repetitive code and changes, if
any, have to be made at one place only.
 Once a function is written and debugged, it can be
reused in other programs as well (using import).

You might also like