SlideShare a Scribd company logo
1 of 20
FUNCTIONS
IN
PYTHON
VENKAT
FACILITATOR
NTH@COPYRIGHT WWW.NATIVETECHHUB.COM
CONTENT
INTRO TO FUNCTIONS
TYPES OF FUNCTIONS
TYPES OF FUNCTIONS
ARGUMENTS
RECURSIVE FUNCTIONS
1
2
3
5
NTH@COPYRIGHT WWW.NATIVETECHHUB.COM
SCOPE OF FUNCTION
VARIABLES
4
Built-In Functions
› Basically Function is a self
contained block of code
which does a specific task.
› It is reusable code
› It is modularity code
› The code which is already
available and derived from
a package or module is
called “Built-in Function”.
Copyright@NTH NTH@PipeLine TO LifeLine
› Ex.
› height=[1.73, 1.68, 1.71,
1.89]
› max(height)
› help(max)
User Defined Function
› Function definition has
“def” keyword followed
function name, function
parameters /arguments
within the parenthesis
followed by colon and
indented blocks of code
in function body.
Copyright@NTH NTH@PipeLine TO LifeLine
› Function are invoked by
a function call by
passing appropriate
parameters
User Defined Function
Copyright@NTH NTH@PipeLine TO LifeLine
User Defined Function
› Rules: To pass
arguments to the
function in Python:
› Arguments are passed by
reference
› Changes made to the formal
parameters would reflect on
to the actual parameters
based on data type called
mutable or immutable
Copyright@NTH NTH@PipeLine TO LifeLine
› In Python
› Immutable Data Types:
› Number, Strings,
Tuples
› Mutable Data Types:
› List, Sets, Dictionary
User Defined Function
› #Immutable data type: number as argument to the function
Copyright@NTH NTH@PipeLine TO LifeLine
User Defined Function
Copyright@NTH NTH@PipeLine TO LifeLine
› Mutable Data type as argument List:
› Required Arguments
› Keyword Arguments
› Default Arguments
› Variable Length Arguments
Various Type of Formal Arguments
Copyright@NTH NTH@PipeLine TO LifeLine
› Required Arguments:
› Arguments follow positional
order
› No. of arguments are same
as function definition
› Order of the arguments as
same as in the function
definition
Copyright@NTH NTH@PipeLine TO LifeLine
› Keyword Arguments:
› When used in functional
call, calling function
identifies the argument by
parameter name
› Allows to change the
positional order of
arguments
› Python Interpreter uses the
keyword provided to
match the values with
parameters
Copyright@NTH NTH@PipeLine TO LifeLine
› Default Arguments:
Consider a default value if the
value is not passed for a
parameter in the function call
Copyright@NTH NTH@PipeLine TO LifeLine
› Variable Length Arguments:
Used to execute functions
with more arguments than
specified during function
definition
Variable arguments will
not have a name while
defining a function when
compared to required and
default arguments
Copyright@NTH NTH@PipeLine TO LifeLine
› Syntax:
› An asterisk “ * “ is located before
variable name to hold all non-
keyword variable arguments.
› * var-args-tuple is empty if no
additional arguments are specified
during functional call
› Variable Length Arguments:
Copyright@NTH NTH@PipeLine TO LifeLine
Scope of Variables
› Determines accessibility of a
variable at various portions of
the program.
› Types of Variables
› Local
› Variables defined
inside the function
have local scope
› Can be accessed only
inside the function in
which it is defined.
Copyright@NTH NTH@PipeLine TO LifeLine
› Global:
› Variables defined outside
the function have global
scope
› Variables can be accessed
throughout the program by
all other functions
Scope of Variables
Copyright@NTH NTH@PipeLine TO LifeLine
Scope of Variables
Copyright@NTH NTH@PipeLine TO LifeLine
› Usage of global keyboard:
› Used to access the variable outside the function
Recursion
› A function called itself is called Recursion
Copyright@NTH NTH@PipeLine TO LifeLine
Lambda Function
› We use lambda functions when we require a nameless function
for a short period of time.
› In Python, we generally use it as an argument to a higher-order
function (a function that takes in other functions as arguments).
› Lambda functions are used along with built-in functions like
filter() , map() etc..
› addresult=lambda a,b:a+b
› print(addresult(10,20))
Copyright@NTH NTH@PipeLine TO LifeLine
Any questions?
You can find me at:
info@nativetechhub.com
#9908133590
Copyright@NTH NTH@PipeLine TO LifeLine

More Related Content

Similar to Functions.pptx Basically Function is a self contained block of code which does a specific task. It is reusable code It is modularity code The code which is already available and derived from a package or module is called “Built-in Function”.

Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C ProgrammingAnil Pokhrel
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxsangeeta borde
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptAmanuelZewdie4
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfDeeptiMalhotra19
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptxManas40552
 
functions modules and exceptions handlings.ppt
functions modules and exceptions handlings.pptfunctions modules and exceptions handlings.ppt
functions modules and exceptions handlings.pptRajasekhar364622
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxGebruGetachew2
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2sumitbardhan
 

Similar to Functions.pptx Basically Function is a self contained block of code which does a specific task. It is reusable code It is modularity code The code which is already available and derived from a package or module is called “Built-in Function”. (20)

Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Functions.pptx
Functions.pptxFunctions.pptx
Functions.pptx
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdf
 
Basic c++
Basic c++Basic c++
Basic c++
 
Function
FunctionFunction
Function
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
functions modules and exceptions handlings.ppt
functions modules and exceptions handlings.pptfunctions modules and exceptions handlings.ppt
functions modules and exceptions handlings.ppt
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
FUNCTIONS.pptx
FUNCTIONS.pptxFUNCTIONS.pptx
FUNCTIONS.pptx
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Python functions
Python   functionsPython   functions
Python functions
 
functions new.pptx
functions new.pptxfunctions new.pptx
functions new.pptx
 
Python Functions
Python FunctionsPython Functions
Python Functions
 
functionnotes.pdf
functionnotes.pdffunctionnotes.pdf
functionnotes.pdf
 
Php, mysq lpart3
Php, mysq lpart3Php, mysq lpart3
Php, mysq lpart3
 
Python-Functions.pptx
Python-Functions.pptxPython-Functions.pptx
Python-Functions.pptx
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

Functions.pptx Basically Function is a self contained block of code which does a specific task. It is reusable code It is modularity code The code which is already available and derived from a package or module is called “Built-in Function”.

  • 2. CONTENT INTRO TO FUNCTIONS TYPES OF FUNCTIONS TYPES OF FUNCTIONS ARGUMENTS RECURSIVE FUNCTIONS 1 2 3 5 NTH@COPYRIGHT WWW.NATIVETECHHUB.COM SCOPE OF FUNCTION VARIABLES 4
  • 3. Built-In Functions › Basically Function is a self contained block of code which does a specific task. › It is reusable code › It is modularity code › The code which is already available and derived from a package or module is called “Built-in Function”. Copyright@NTH NTH@PipeLine TO LifeLine › Ex. › height=[1.73, 1.68, 1.71, 1.89] › max(height) › help(max)
  • 4. User Defined Function › Function definition has “def” keyword followed function name, function parameters /arguments within the parenthesis followed by colon and indented blocks of code in function body. Copyright@NTH NTH@PipeLine TO LifeLine › Function are invoked by a function call by passing appropriate parameters
  • 5. User Defined Function Copyright@NTH NTH@PipeLine TO LifeLine
  • 6. User Defined Function › Rules: To pass arguments to the function in Python: › Arguments are passed by reference › Changes made to the formal parameters would reflect on to the actual parameters based on data type called mutable or immutable Copyright@NTH NTH@PipeLine TO LifeLine › In Python › Immutable Data Types: › Number, Strings, Tuples › Mutable Data Types: › List, Sets, Dictionary
  • 7. User Defined Function › #Immutable data type: number as argument to the function Copyright@NTH NTH@PipeLine TO LifeLine
  • 8. User Defined Function Copyright@NTH NTH@PipeLine TO LifeLine › Mutable Data type as argument List:
  • 9. › Required Arguments › Keyword Arguments › Default Arguments › Variable Length Arguments Various Type of Formal Arguments Copyright@NTH NTH@PipeLine TO LifeLine
  • 10. › Required Arguments: › Arguments follow positional order › No. of arguments are same as function definition › Order of the arguments as same as in the function definition Copyright@NTH NTH@PipeLine TO LifeLine
  • 11. › Keyword Arguments: › When used in functional call, calling function identifies the argument by parameter name › Allows to change the positional order of arguments › Python Interpreter uses the keyword provided to match the values with parameters Copyright@NTH NTH@PipeLine TO LifeLine
  • 12. › Default Arguments: Consider a default value if the value is not passed for a parameter in the function call Copyright@NTH NTH@PipeLine TO LifeLine
  • 13. › Variable Length Arguments: Used to execute functions with more arguments than specified during function definition Variable arguments will not have a name while defining a function when compared to required and default arguments Copyright@NTH NTH@PipeLine TO LifeLine › Syntax: › An asterisk “ * “ is located before variable name to hold all non- keyword variable arguments. › * var-args-tuple is empty if no additional arguments are specified during functional call
  • 14. › Variable Length Arguments: Copyright@NTH NTH@PipeLine TO LifeLine
  • 15. Scope of Variables › Determines accessibility of a variable at various portions of the program. › Types of Variables › Local › Variables defined inside the function have local scope › Can be accessed only inside the function in which it is defined. Copyright@NTH NTH@PipeLine TO LifeLine › Global: › Variables defined outside the function have global scope › Variables can be accessed throughout the program by all other functions
  • 16. Scope of Variables Copyright@NTH NTH@PipeLine TO LifeLine
  • 17. Scope of Variables Copyright@NTH NTH@PipeLine TO LifeLine › Usage of global keyboard: › Used to access the variable outside the function
  • 18. Recursion › A function called itself is called Recursion Copyright@NTH NTH@PipeLine TO LifeLine
  • 19. Lambda Function › We use lambda functions when we require a nameless function for a short period of time. › In Python, we generally use it as an argument to a higher-order function (a function that takes in other functions as arguments). › Lambda functions are used along with built-in functions like filter() , map() etc.. › addresult=lambda a,b:a+b › print(addresult(10,20)) Copyright@NTH NTH@PipeLine TO LifeLine
  • 20. Any questions? You can find me at: info@nativetechhub.com #9908133590 Copyright@NTH NTH@PipeLine TO LifeLine