SlideShare a Scribd company logo
5
Most read
7
Most read
17
Most read
PRESENTED BY,
RONAK RATHI & SAMIR
RAWAT.
OBJECTIVE
HOW TO DEFINE A FUNCTION
HOW TO CALL A FUNCTION
FUNCTION ARGUMENTS
FUNCTION RECURSION
FUNCTION
 FUNCTION IS A GROUP OF RELATED
STATEMENTS THAT PERFORM A SPECIFIC TASK
 FUNCTIONS HELP BREAK OUR PROGRAM INTO
SMALLER AND MODULAR CHUCKS
DEFINING FUNCTION
def marks the start of function
function name to uniquely
identify a function.
def function_name (parameter) :
Argument to pass a value in function
colon(:) to mark end of
function header
EXAMPLE OF FUNCTION
def greet (name):
print(“Hello,” + name +” . Good afternoon!”)
CALLING A FUNCTION
HOW TO CALL A 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 parameters.
>>> greet(“everyone")
>>>Hello, everyone. Good afternoon!
EXAMPLE
def my_func():
x = 10
global y
y = 20
print("Value of y inside function:",x)
print("Value of y inside function:",y)
x = 20
y = 10
my_func()
print("Value of y outside function:",x)
print("Value of y outside function:",y)
THERE ARE TWO TYPES OF FUNCTION IN PYTHON
 BUILT-IN FUNCTION
Example: print(), input(), eval().
 USERDEFINE FUNCTION
Example: def my_addition(x,y):
sum = x + y
return sum
 FUNCTION BUILT WITHIN THE PYTHON.
 THERE ARE 68 BUILT-IN FUNCTION VERSION 3.4.
 CHANGES WITH RESPECT TO UPDATED VERSION.
VARIABLE
FUNCTION
ARGUMENTS
DEFAULT
ARGUMENT
KEYWORD
ARGUMENT
ARBITRARY
ARGUMENTS
DEFAULT ARGUMENTS
 Default value to function argument is passed using
assignment operator ‘ = ‘.
Example:
def greet(name, msg = "Good morning!"):
print("Hello, " name + ', ' + msg)
 Non-default argument cannot follow default argument
Example: def greet(msg = "Good morning!", name):
SyntaxError:
non-default argument follows default argument
KEYWORD ARGUMENTS
 When we call a function with some values, these
values get assigned to the arguments according to their
position .
 Keyword arguments follows positional argument.
EXAMPLE OF KEYWORD
ARGUMENT
 greet(name = "Bruce",msg = "How do you do?")
2 keyword arguments
 greet(msg = "How do you do?",name = "Bruce")
2 keyword arguments (out of order)
 greet("Bruce",msg = "How do you do?")
1 positional, 1 keyword argument
 greet(name="Bruce","How do you do?")
SyntaxError:
non-keyword arg after keyword arg
 If number of arguments unknown we use arbitrary
arguments
 ( * ) Asterisk before arguments define arbitrary arguments.
Example:
def greet(*names):
for name in names:
print("Hello",name)
>>>greet("Monica","Luke","Steve","John")
ARBITRARY ARGUMENTS
 Like other programming language in python, function
can call itself.
 Definition of recursion in python is same as other
programming lang. -> C, C++, C#, Java etc.
def recur_fact(x):
if x == 1:
return 1
else:
return (x * recur_fact(x-1))
num = int(input("Enter a number: "))
if num >= 1:
print("The factorial of", num, "is", recur_fact(num))
EXAMPLE OF RECURSION
 Function without function name.
 Function is defined using lambda keyword, hence
function is also called Lambda function.
 Used for short period in python.
 Can have any number of arguments but only single
expression.
 Specially used with built-in functions like filter(),
map() etc.
ANONYMOUS
 double = lambda x: x * 2 print(double(5))
 my_list = [1, 5, 4, 6, 8, 11, 3, 12]
new_list = list(filter(lambda x: (x%2 == 0) , my_list))
print(new_list)
EXAMPLE OF LAMBDA
FUNCTION
RESOURCES
 www.programiz.com/python-programming
 https://wiki.python.org/moin/BeginnersGuide/Progra
mmers
THANK YOU
HAVE A NICE DAY!

More Related Content

PDF
Giáo trình lập trình Python căn bản - Trần Nhật Quang, Phạm Văn Khoa.pdf
Man_Ebook
 
PPTX
File handling in Python
Megha V
 
PPTX
Functions in python slide share
Devashish Kumar
 
PDF
Strings in python
Prabhakaran V M
 
PDF
Python : Regular expressions
Emertxe Information Technologies Pvt Ltd
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
Python: Modules and Packages
Damian T. Gordon
 
PDF
Internet of Things (IoT) - We Are at the Tip of An Iceberg
Dr. Mazlan Abbas
 
Giáo trình lập trình Python căn bản - Trần Nhật Quang, Phạm Văn Khoa.pdf
Man_Ebook
 
File handling in Python
Megha V
 
Functions in python slide share
Devashish Kumar
 
Strings in python
Prabhakaran V M
 
Python : Regular expressions
Emertxe Information Technologies Pvt Ltd
 
Python Functions
Mohammed Sikander
 
Python: Modules and Packages
Damian T. Gordon
 
Internet of Things (IoT) - We Are at the Tip of An Iceberg
Dr. Mazlan Abbas
 

What's hot (20)

PPTX
Functions in Python
Kamal Acharya
 
PDF
Python functions
Prof. Dr. K. Adisesha
 
PPTX
Chapter 07 inheritance
Praveen M Jigajinni
 
PPSX
Modules and packages in python
TMARAGATHAM
 
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
PPTX
Variables in python
Jaya Kumari
 
PPTX
Chapter 05 classes and objects
Praveen M Jigajinni
 
PPTX
Functions in c
sunila tharagaturi
 
PDF
Python tuple
Mohammed Sikander
 
PPTX
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
PPTX
Values and Data types in python
Jothi Thilaga P
 
PPT
Method overriding
Azaz Maverick
 
PPTX
Java constructors
QUONTRASOLUTIONS
 
PPTX
Pass by value and pass by reference
TurnToTech
 
PDF
Python Flow Control
Mohammed Sikander
 
PDF
Class and Objects in Java
Spotle.ai
 
PPTX
Tuple in python
Sharath Ankrajegowda
 
PPTX
Data types in java
HarshitaAshwani
 
PPTX
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
PPTX
Functions in Python
Shakti Singh Rathore
 
Functions in Python
Kamal Acharya
 
Python functions
Prof. Dr. K. Adisesha
 
Chapter 07 inheritance
Praveen M Jigajinni
 
Modules and packages in python
TMARAGATHAM
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Variables in python
Jaya Kumari
 
Chapter 05 classes and objects
Praveen M Jigajinni
 
Functions in c
sunila tharagaturi
 
Python tuple
Mohammed Sikander
 
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Values and Data types in python
Jothi Thilaga P
 
Method overriding
Azaz Maverick
 
Java constructors
QUONTRASOLUTIONS
 
Pass by value and pass by reference
TurnToTech
 
Python Flow Control
Mohammed Sikander
 
Class and Objects in Java
Spotle.ai
 
Tuple in python
Sharath Ankrajegowda
 
Data types in java
HarshitaAshwani
 
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Functions in Python
Shakti Singh Rathore
 
Ad

Viewers also liked (14)

PDF
Function arguments In Python
Amit Upadhyay
 
PPTX
Basics of Object Oriented Programming in Python
Sujith Kumar
 
PDF
Descriptors In Python
Amit Upadhyay
 
ODP
Day2
Karin Lagesen
 
PDF
Functions
Marieswaran Ramasamy
 
PDF
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
PDF
Input and Output
Marieswaran Ramasamy
 
PPTX
Python datatype
건희 김
 
PDF
4. python functions
in4400
 
ODP
Python Modules
Nitin Reddy Katkam
 
PDF
Functions in python
Ilian Iliev
 
PDF
Functions and modules in python
Karin Lagesen
 
PPTX
Print input-presentation
Martin McBride
 
Function arguments In Python
Amit Upadhyay
 
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Descriptors In Python
Amit Upadhyay
 
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Input and Output
Marieswaran Ramasamy
 
Python datatype
건희 김
 
4. python functions
in4400
 
Python Modules
Nitin Reddy Katkam
 
Functions in python
Ilian Iliev
 
Functions and modules in python
Karin Lagesen
 
Print input-presentation
Martin McBride
 
Ad

Similar to python Function (20)

PPTX
functions.pptxghhhhhhhhhhhhhhhffhhhhhhhdf
pawankamal3
 
PPTX
Functions in python3
Lakshmi Sarvani Videla
 
PDF
Python basic
Saifuddin Kaijar
 
PDF
Class 7a: Functions
Marc Gouw
 
PPTX
Functions in Python with all type of arguments
riazahamed37
 
PPTX
Functions in Python Programming Language
BeulahS2
 
PPTX
Working with functions.pptx. Hb.
sabarivelan111007
 
PDF
beginners_python_cheat_sheet_pcc_functions.pdf
GuarachandarChand
 
PPTX
Lecture 08.pptx
Mohammad Hassan
 
PPTX
UNIT 3 python.pptx
TKSanthoshRao
 
PPTX
functions new.pptx
bhuvanalakshmik2
 
PDF
Function in Python
Yashdev Hada
 
PPTX
2 Functions2.pptx
RohitYadav830391
 
PDF
functionnotes.pdf
AXL Computer Academy
 
PPTX
CHAPTER 01 FUNCTION in python class 12th.pptx
PreeTVithule1
 
PPTX
Py-slides-3 easyforbeginnerspythoncourse.pptx
mohamedsamydeveloper
 
PPTX
UNIT- 2 PPDS R20.pptx
ssuser688516
 
PPTX
JNTUK python programming python unit 3.pptx
Venkateswara Babu Ravipati
 
PPTX
Python PCEP Function Parameters
IHTMINSTITUTE
 
functions.pptxghhhhhhhhhhhhhhhffhhhhhhhdf
pawankamal3
 
Functions in python3
Lakshmi Sarvani Videla
 
Python basic
Saifuddin Kaijar
 
Class 7a: Functions
Marc Gouw
 
Functions in Python with all type of arguments
riazahamed37
 
Functions in Python Programming Language
BeulahS2
 
Working with functions.pptx. Hb.
sabarivelan111007
 
beginners_python_cheat_sheet_pcc_functions.pdf
GuarachandarChand
 
Lecture 08.pptx
Mohammad Hassan
 
UNIT 3 python.pptx
TKSanthoshRao
 
functions new.pptx
bhuvanalakshmik2
 
Function in Python
Yashdev Hada
 
2 Functions2.pptx
RohitYadav830391
 
functionnotes.pdf
AXL Computer Academy
 
CHAPTER 01 FUNCTION in python class 12th.pptx
PreeTVithule1
 
Py-slides-3 easyforbeginnerspythoncourse.pptx
mohamedsamydeveloper
 
UNIT- 2 PPDS R20.pptx
ssuser688516
 
JNTUK python programming python unit 3.pptx
Venkateswara Babu Ravipati
 
Python PCEP Function Parameters
IHTMINSTITUTE
 

Recently uploaded (20)

PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PDF
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
The Asian School
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
Information Retrieval and Extraction - Module 7
premSankar19
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
The Asian School
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 

python Function

  • 1. PRESENTED BY, RONAK RATHI & SAMIR RAWAT.
  • 2. OBJECTIVE HOW TO DEFINE A FUNCTION HOW TO CALL A FUNCTION FUNCTION ARGUMENTS FUNCTION RECURSION
  • 3. FUNCTION  FUNCTION IS A GROUP OF RELATED STATEMENTS THAT PERFORM A SPECIFIC TASK  FUNCTIONS HELP BREAK OUR PROGRAM INTO SMALLER AND MODULAR CHUCKS
  • 4. DEFINING FUNCTION def marks the start of function function name to uniquely identify a function. def function_name (parameter) : Argument to pass a value in function colon(:) to mark end of function header
  • 5. EXAMPLE OF FUNCTION def greet (name): print(“Hello,” + name +” . Good afternoon!”)
  • 6. CALLING A FUNCTION HOW TO CALL A 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 parameters. >>> greet(“everyone") >>>Hello, everyone. Good afternoon!
  • 7. EXAMPLE def my_func(): x = 10 global y y = 20 print("Value of y inside function:",x) print("Value of y inside function:",y) x = 20 y = 10 my_func() print("Value of y outside function:",x) print("Value of y outside function:",y)
  • 8. THERE ARE TWO TYPES OF FUNCTION IN PYTHON  BUILT-IN FUNCTION Example: print(), input(), eval().  USERDEFINE FUNCTION Example: def my_addition(x,y): sum = x + y return sum
  • 9.  FUNCTION BUILT WITHIN THE PYTHON.  THERE ARE 68 BUILT-IN FUNCTION VERSION 3.4.  CHANGES WITH RESPECT TO UPDATED VERSION.
  • 11. DEFAULT ARGUMENTS  Default value to function argument is passed using assignment operator ‘ = ‘. Example: def greet(name, msg = "Good morning!"): print("Hello, " name + ', ' + msg)  Non-default argument cannot follow default argument Example: def greet(msg = "Good morning!", name): SyntaxError: non-default argument follows default argument
  • 12. KEYWORD ARGUMENTS  When we call a function with some values, these values get assigned to the arguments according to their position .  Keyword arguments follows positional argument.
  • 13. EXAMPLE OF KEYWORD ARGUMENT  greet(name = "Bruce",msg = "How do you do?") 2 keyword arguments  greet(msg = "How do you do?",name = "Bruce") 2 keyword arguments (out of order)  greet("Bruce",msg = "How do you do?") 1 positional, 1 keyword argument  greet(name="Bruce","How do you do?") SyntaxError: non-keyword arg after keyword arg
  • 14.  If number of arguments unknown we use arbitrary arguments  ( * ) Asterisk before arguments define arbitrary arguments. Example: def greet(*names): for name in names: print("Hello",name) >>>greet("Monica","Luke","Steve","John") ARBITRARY ARGUMENTS
  • 15.  Like other programming language in python, function can call itself.  Definition of recursion in python is same as other programming lang. -> C, C++, C#, Java etc.
  • 16. def recur_fact(x): if x == 1: return 1 else: return (x * recur_fact(x-1)) num = int(input("Enter a number: ")) if num >= 1: print("The factorial of", num, "is", recur_fact(num)) EXAMPLE OF RECURSION
  • 17.  Function without function name.  Function is defined using lambda keyword, hence function is also called Lambda function.  Used for short period in python.  Can have any number of arguments but only single expression.  Specially used with built-in functions like filter(), map() etc. ANONYMOUS
  • 18.  double = lambda x: x * 2 print(double(5))  my_list = [1, 5, 4, 6, 8, 11, 3, 12] new_list = list(filter(lambda x: (x%2 == 0) , my_list)) print(new_list) EXAMPLE OF LAMBDA FUNCTION
  • 20. THANK YOU HAVE A NICE DAY!