5
Most read
7
Most read
10
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

PPTX
Functions in python slide share
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
PPTX
Python Functions
PPTX
USER DEFINE FUNCTIONS IN PYTHON
PPTX
trees in data structure
PDF
Python functions
PPTX
Machine learning ppt
PPTX
Terminal Commands (Linux - ubuntu) (part-1)
Functions in python slide share
Giáo trình lập trình Python căn bản - Trần Nhật Quang, Phạm Văn Khoa.pdf
Python Functions
USER DEFINE FUNCTIONS IN PYTHON
trees in data structure
Python functions
Machine learning ppt
Terminal Commands (Linux - ubuntu) (part-1)

What's hot (20)

PPTX
Function in C program
PPTX
Python OOPs
PDF
Python strings
PPTX
Functions in Python
PPTX
Strings in C
PPTX
Pointers in c++
PPTX
Strings in C language
PDF
Tuples in Python
PPT
Python GUI Programming
PPTX
Union in C programming
PPTX
File in C language
PDF
Python recursion
PPTX
Polymorphism in Python
PPTX
Class, object and inheritance in python
PPTX
Array and string
PPTX
Functions in c
PDF
Python list
PDF
List,tuple,dictionary
PPTX
Pointer in C++
Function in C program
Python OOPs
Python strings
Functions in Python
Strings in C
Pointers in c++
Strings in C language
Tuples in Python
Python GUI Programming
Union in C programming
File in C language
Python recursion
Polymorphism in Python
Class, object and inheritance in python
Array and string
Functions in c
Python list
List,tuple,dictionary
Pointer in C++
Ad

Viewers also liked (13)

PDF
Function arguments In Python
PPTX
Basics of Object Oriented Programming in Python
PDF
Descriptors In Python
ODP
PDF
PDF
Python Functions (PyAtl Beginners Night)
PDF
Input and Output
PPTX
Python datatype
PDF
4. python functions
ODP
Python Modules
PDF
Functions in python
PDF
Functions and modules in python
PPTX
Print input-presentation
Function arguments In Python
Basics of Object Oriented Programming in Python
Descriptors In Python
Python Functions (PyAtl Beginners Night)
Input and Output
Python datatype
4. python functions
Python Modules
Functions in python
Functions and modules in python
Print input-presentation
Ad

Similar to python Function (20)

PPTX
functions.pptxghhhhhhhhhhhhhhhffhhhhhhhdf
PPTX
Functions in python3
PDF
Python basic
PDF
Class 7a: Functions
PPTX
Functions in Python with all type of arguments
PPTX
Functions in Python Programming Language
PPTX
Working with functions.pptx. Hb.
PDF
beginners_python_cheat_sheet_pcc_functions.pdf
PPTX
Lecture 08.pptx
PPTX
UNIT 3 python.pptx
PPTX
functions new.pptx
PDF
Function in Python
PPTX
2 Functions2.pptx
PPTX
CSE110_week_8.1_NAD kjgkarglkanrglakerngkl.pptx
PDF
functionnotes.pdf
PPTX
CHAPTER 01 FUNCTION in python class 12th.pptx
PPTX
Py-slides-3 easyforbeginnerspythoncourse.pptx
PPTX
UNIT- 2 PPDS R20.pptx
PPTX
JNTUK python programming python unit 3.pptx
functions.pptxghhhhhhhhhhhhhhhffhhhhhhhdf
Functions in python3
Python basic
Class 7a: Functions
Functions in Python with all type of arguments
Functions in Python Programming Language
Working with functions.pptx. Hb.
beginners_python_cheat_sheet_pcc_functions.pdf
Lecture 08.pptx
UNIT 3 python.pptx
functions new.pptx
Function in Python
2 Functions2.pptx
CSE110_week_8.1_NAD kjgkarglkanrglakerngkl.pptx
functionnotes.pdf
CHAPTER 01 FUNCTION in python class 12th.pptx
Py-slides-3 easyforbeginnerspythoncourse.pptx
UNIT- 2 PPDS R20.pptx
JNTUK python programming python unit 3.pptx

Recently uploaded (20)

PDF
M01-Manage Safety and Environmental Protection 1.pdf
PDF
Human CELLS and structure in Anatomy and human physiology
PDF
ITEC 1010 - Information and Organizations Database System and Big data
PDF
IoT-Based Hybrid Renewable Energy System.pdf
PDF
02. INDUSTRIAL REVOLUTION & Cultural, Technical and territorial transformatio...
PPTX
Soumya Das post quantum crypot algorithm
PDF
Recent Trends in Network Security - 2025
PDF
Operating systems-POS-U1.2.pdf cse gghhu
PDF
August 2025 Top read articles in International Journal of Database Managemen...
PDF
IMDb_Product_Teardown_product_management
PPTX
sinteringn kjfnvkjdfvkdfnoeneornvoirjoinsonosjf).pptx
PPTX
Retail.pptx internet of things mtech 2 nd sem
PPT
Module_1_Lecture_1_Introduction_To_Automation_In_Production_Systems2023.ppt
PDF
Thesis of the Fruit Harvesting Robot .pdf
PDF
The Journal of Finance - July 1993 - JENSEN - The Modern Industrial Revolutio...
PPTX
Embedded Systems Microcontrollers and Microprocessors.pptx
PDF
Application of smart robotics in the supply chain
PDF
B461227.pdf American Journal of Multidisciplinary Research and Review
PPTX
240409 Data Center Training Programs by Uptime Institute (Drafting).pptx
PDF
Disaster Management_Lecture_ PPT_Dr. Kunjari Mog, NITH.pdf
M01-Manage Safety and Environmental Protection 1.pdf
Human CELLS and structure in Anatomy and human physiology
ITEC 1010 - Information and Organizations Database System and Big data
IoT-Based Hybrid Renewable Energy System.pdf
02. INDUSTRIAL REVOLUTION & Cultural, Technical and territorial transformatio...
Soumya Das post quantum crypot algorithm
Recent Trends in Network Security - 2025
Operating systems-POS-U1.2.pdf cse gghhu
August 2025 Top read articles in International Journal of Database Managemen...
IMDb_Product_Teardown_product_management
sinteringn kjfnvkjdfvkdfnoeneornvoirjoinsonosjf).pptx
Retail.pptx internet of things mtech 2 nd sem
Module_1_Lecture_1_Introduction_To_Automation_In_Production_Systems2023.ppt
Thesis of the Fruit Harvesting Robot .pdf
The Journal of Finance - July 1993 - JENSEN - The Modern Industrial Revolutio...
Embedded Systems Microcontrollers and Microprocessors.pptx
Application of smart robotics in the supply chain
B461227.pdf American Journal of Multidisciplinary Research and Review
240409 Data Center Training Programs by Uptime Institute (Drafting).pptx
Disaster Management_Lecture_ PPT_Dr. Kunjari Mog, NITH.pdf

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!