SlideShare a Scribd company logo
Devashish Kumar
Faculty-IT
iNurture
FUNCTIONS
 A function is a block of organized, reusable code that is
used to perform a single, related action.
 Functions provide better modularity for the applications.
 Functions provide a high degree of code reusing.
RULES FOR DEFINING FUNCTION IN PYTHON
 Function blocks begin with the keyword def followed by the function name and
parentheses ( ( ) ).
 Any input parameters or arguments should be placed within these parentheses.
We also define parameters inside these parentheses.
 The code block within every function starts with a colon (:) and is indented.
 The statement return [expression] exits a function, optionally passing back an
expression to the caller.
 A return statement with no arguments is the same as return None.
Function Syntax
The keyword
def
introduces a
function
definition.
Input Parameter is placed within the
parenthesis() and also define
parameter inside the parenthesis.
Return statement exits a
function block. And we can also
use return with no argument.
The code block
within every
function starts
with a colon(:) .
Functions in python slide share
PASSING ARGUMENTS TO FUNCTIONS
 In programming, there are two ways in which arguments can be passed to functions :-
 Pass by Value:
 Function creates a copy of the variable(Object in Python) passed to it as an argument.
 The actual object is not affected.
 Object is of immutable type,because immutable objects cannot be modified.
 Pass by Reference:
 The actual object is passed to the called function.
 All the changes made to the object inside the function affect its original value.
 Object is mutable type, as mutable objects can be changed, the passed objects are
updated.
EXAMPLES OF PASSING IMMUTABLE ARGUMENTS
OUTPUT: New memory address of ‘a’
inside the function.
Actual variable ‘a’ is not
changed.
EXAMPLES OF PASSING MUTABLE ARGUMENTS
Address is same
Value of my_list is
changed after
function call.
FUNCTION ARGUMENTS
DEFAULT ARGUMENT VALUES
 Default Argument- argument that assumes a default value if a value is not
provided in the function call for that argument.
 The default value is evaluated only once.
 EXAMPLE:
Output:
In this code, argument ‘b’
has given a default value.
ie(b=90)
When the value of ‘b’ is not passed
in function ,then it takes default
argument.
DEFAULT ARGUMENTS
 The default value is evaluated only once. This makes a difference when the
default is a mutable object such as a list, dictionary, or instances of most
classes.
 Example:
 if we don’t want the default value to be shared between subsequent calls,
then
 Example :
Output:
Output:
KEYWORD ARGUMENTS
 Keyword arguments are related to the function calls.
 Using keyword arguments in a function call, the caller identifies the arguments
by the parameter name.
 Allows to skip arguments or place them out of order, the Python interpreter
use the keywords provided to match the values with parameters.
 Example:
Output:
 Caller identifies the keyword
argument by the parameter name.
 Calling of the argument Order
doesn’t matter .
KEYWORD ARGUMENTS
 Example 1:
Output:
Example 2: Output:
ARBITRARY ARGUMENT LISTS
 Variable-Length Arguments: more arguments than we specified while defining
the function.
 These arguments are also called variable-length arguments .
 An asterisk (*) is placed before the variable name that holds the values of all non
keyword variable arguments.
 This tuple remains empty if no additional arguments are specified during the
function call.
 Syntax :
def function_name([formal_args], *var_args_tuple ):
statement 1……
statement 2……
return [expression]
This is called
arbitrary argument
and asterisk sign is
placed before the
variable name.
ARBITRARY ARGUMENT LISTS
 EXAMPLE 1:
Output: Output:
 EXAMPLE 2:
 Any formal parameter which
occur after the *args
parameter are keyword-only
arguments.
 If formal parameter are not
keyword argument then error
occurred.
UNPACKING ARGUMENT LISTS
 Arguments are already in a list or tuple, need to be unpacked for a function
call requiring separate positional arguments.
 For instance, the built-in range() function expects separate start and stop
arguments.
 If range() are not available separately, write the function call with the *-operator
to unpack the arguments out of a list or tuple.
 Example 1: Example 2:
Output:
In dictionary, we use ‘**’ for unpacking the
arguments
In tuples or lists, ‘*’ is
used to unpack the
arguments
LAMBDA EXPRESSIONS
 Small functions can be created with the lambda keyword also known as
Anonymous function.
 Used wherever functions object are required.
 These functions are called anonymous because they are not declared in the
standard manner by using the def keyword. .
 Syntax :
 EXAMPLE:
lambda [arg1 [,arg2,.....argn]]:expression
Output:
 The function returns the multiply of
two arguments.
 Lambda function is restricted to a
single expressions.
FUNCTION ANNOTATIONS
 Function annotations are completely optional metadata information about the
types used by user-defined functions.
 Annotations are stored in the “__annotations__” attribute .
 Parameter annotations are defined by a colon after the parameter name,
followed by an expression evaluating to the value of the annotation.
 Return annotations are defined by a literal ->, followed by an expression,
between the parameter list and the colon denoting the end of the def statement.
 Example:
Output:
Literal ‘->’ is used to
define return
annotations.
DOCUMENTATION STRINGS
 The first line should always be a short, concise summary of the object’s
purpose.
 The first line should begin with a capital letter and end with a period.
 If there are more lines in the documentation string, the second line should be
blank.
 The first non-blank line after the first line of the string determines the amount
of indentation for the entire documentation string.
 Example:
Output:
‘.doc’ is used to print the
documentation strings.
CONTRIBUTERS
Ad

More Related Content

What's hot (20)

List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
RaginiJain21
 
Functions in python
Functions in pythonFunctions in python
Functions in python
colorsof
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
Mohammed Sikander
 
Python functions
Python functionsPython functions
Python functions
Prof. Dr. K. Adisesha
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Kamal Acharya
 
Recursion
RecursionRecursion
Recursion
Abdur Rehman
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
baabtra.com - No. 1 supplier of quality freshers
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
Prof. Dr. K. Adisesha
 
Type conversion
Type conversionType conversion
Type conversion
Frijo Francis
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 

Similar to Functions in python slide share (20)

functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
Osama Ghandour Geris
 
functions notes.pdf python functions and opp
functions notes.pdf python functions and oppfunctions notes.pdf python functions and opp
functions notes.pdf python functions and opp
KirtiGarg71
 
Py-Slides-3 difficultpythoncoursefforbeginners.ppt
Py-Slides-3 difficultpythoncoursefforbeginners.pptPy-Slides-3 difficultpythoncoursefforbeginners.ppt
Py-Slides-3 difficultpythoncoursefforbeginners.ppt
mohamedsamydeveloper
 
functionnotes.pdf
functionnotes.pdffunctionnotes.pdf
functionnotes.pdf
AXL Computer Academy
 
Powerpoint presentation for Python Functions
Powerpoint presentation for Python FunctionsPowerpoint presentation for Python Functions
Powerpoint presentation for Python Functions
BalaSubramanian376976
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuples
MalligaarjunanN
 
python slides introduction interrupt.ppt
python slides introduction interrupt.pptpython slides introduction interrupt.ppt
python slides introduction interrupt.ppt
Vinod Deenathayalan
 
Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdf
DeeptiMalhotra19
 
Learn more about the concepts Functions of Python
Learn more about the concepts Functions of PythonLearn more about the concepts Functions of Python
Learn more about the concepts Functions of Python
PrathamKandari
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
MalligaarjunanN
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
KavithaChekuri3
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
Functions
FunctionsFunctions
Functions
Septi Ratnasari
 
10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD
10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD
10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD
RuzelAmpoan1
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
Praveen M Jigajinni
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
AnuragBharti27
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
AnuragBharti27
 
functions new.pptx
functions new.pptxfunctions new.pptx
functions new.pptx
bhuvanalakshmik2
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
programlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jgprogramlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jg
uleAmet
 
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
Osama Ghandour Geris
 
functions notes.pdf python functions and opp
functions notes.pdf python functions and oppfunctions notes.pdf python functions and opp
functions notes.pdf python functions and opp
KirtiGarg71
 
Py-Slides-3 difficultpythoncoursefforbeginners.ppt
Py-Slides-3 difficultpythoncoursefforbeginners.pptPy-Slides-3 difficultpythoncoursefforbeginners.ppt
Py-Slides-3 difficultpythoncoursefforbeginners.ppt
mohamedsamydeveloper
 
Powerpoint presentation for Python Functions
Powerpoint presentation for Python FunctionsPowerpoint presentation for Python Functions
Powerpoint presentation for Python Functions
BalaSubramanian376976
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuples
MalligaarjunanN
 
python slides introduction interrupt.ppt
python slides introduction interrupt.pptpython slides introduction interrupt.ppt
python slides introduction interrupt.ppt
Vinod Deenathayalan
 
Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdf
DeeptiMalhotra19
 
Learn more about the concepts Functions of Python
Learn more about the concepts Functions of PythonLearn more about the concepts Functions of Python
Learn more about the concepts Functions of Python
PrathamKandari
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
MalligaarjunanN
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD
10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD
10 Functions.pptx DSDFDFDFDFDFDFDFDFFDFDFD
RuzelAmpoan1
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
programlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jgprogramlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jg
uleAmet
 
Ad

More from Devashish Kumar (6)

Python: Data Visualisation
Python: Data  VisualisationPython: Data  Visualisation
Python: Data Visualisation
Devashish Kumar
 
Pandas csv
Pandas csvPandas csv
Pandas csv
Devashish Kumar
 
Data Analysis packages
Data Analysis packagesData Analysis packages
Data Analysis packages
Devashish Kumar
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
Devashish Kumar
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
Devashish Kumar
 
Cloud Computing Introductory-1
Cloud Computing Introductory-1Cloud Computing Introductory-1
Cloud Computing Introductory-1
Devashish Kumar
 
Python: Data Visualisation
Python: Data  VisualisationPython: Data  Visualisation
Python: Data Visualisation
Devashish Kumar
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
Devashish Kumar
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
Devashish Kumar
 
Cloud Computing Introductory-1
Cloud Computing Introductory-1Cloud Computing Introductory-1
Cloud Computing Introductory-1
Devashish Kumar
 
Ad

Recently uploaded (20)

CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxLecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Arshad Shaikh
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxLecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Arshad Shaikh
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 

Functions in python slide share

  • 2. FUNCTIONS  A function is a block of organized, reusable code that is used to perform a single, related action.  Functions provide better modularity for the applications.  Functions provide a high degree of code reusing.
  • 3. RULES FOR DEFINING FUNCTION IN PYTHON  Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).  Any input parameters or arguments should be placed within these parentheses. We also define parameters inside these parentheses.  The code block within every function starts with a colon (:) and is indented.  The statement return [expression] exits a function, optionally passing back an expression to the caller.  A return statement with no arguments is the same as return None.
  • 4. Function Syntax The keyword def introduces a function definition. Input Parameter is placed within the parenthesis() and also define parameter inside the parenthesis. Return statement exits a function block. And we can also use return with no argument. The code block within every function starts with a colon(:) .
  • 6. PASSING ARGUMENTS TO FUNCTIONS  In programming, there are two ways in which arguments can be passed to functions :-  Pass by Value:  Function creates a copy of the variable(Object in Python) passed to it as an argument.  The actual object is not affected.  Object is of immutable type,because immutable objects cannot be modified.  Pass by Reference:  The actual object is passed to the called function.  All the changes made to the object inside the function affect its original value.  Object is mutable type, as mutable objects can be changed, the passed objects are updated.
  • 7. EXAMPLES OF PASSING IMMUTABLE ARGUMENTS OUTPUT: New memory address of ‘a’ inside the function. Actual variable ‘a’ is not changed.
  • 8. EXAMPLES OF PASSING MUTABLE ARGUMENTS Address is same Value of my_list is changed after function call.
  • 10. DEFAULT ARGUMENT VALUES  Default Argument- argument that assumes a default value if a value is not provided in the function call for that argument.  The default value is evaluated only once.  EXAMPLE: Output: In this code, argument ‘b’ has given a default value. ie(b=90) When the value of ‘b’ is not passed in function ,then it takes default argument.
  • 11. DEFAULT ARGUMENTS  The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes.  Example:  if we don’t want the default value to be shared between subsequent calls, then  Example : Output: Output:
  • 12. KEYWORD ARGUMENTS  Keyword arguments are related to the function calls.  Using keyword arguments in a function call, the caller identifies the arguments by the parameter name.  Allows to skip arguments or place them out of order, the Python interpreter use the keywords provided to match the values with parameters.  Example: Output:  Caller identifies the keyword argument by the parameter name.  Calling of the argument Order doesn’t matter .
  • 13. KEYWORD ARGUMENTS  Example 1: Output: Example 2: Output:
  • 14. ARBITRARY ARGUMENT LISTS  Variable-Length Arguments: more arguments than we specified while defining the function.  These arguments are also called variable-length arguments .  An asterisk (*) is placed before the variable name that holds the values of all non keyword variable arguments.  This tuple remains empty if no additional arguments are specified during the function call.  Syntax : def function_name([formal_args], *var_args_tuple ): statement 1…… statement 2…… return [expression] This is called arbitrary argument and asterisk sign is placed before the variable name.
  • 15. ARBITRARY ARGUMENT LISTS  EXAMPLE 1: Output: Output:  EXAMPLE 2:  Any formal parameter which occur after the *args parameter are keyword-only arguments.  If formal parameter are not keyword argument then error occurred.
  • 16. UNPACKING ARGUMENT LISTS  Arguments are already in a list or tuple, need to be unpacked for a function call requiring separate positional arguments.  For instance, the built-in range() function expects separate start and stop arguments.  If range() are not available separately, write the function call with the *-operator to unpack the arguments out of a list or tuple.  Example 1: Example 2: Output: In dictionary, we use ‘**’ for unpacking the arguments In tuples or lists, ‘*’ is used to unpack the arguments
  • 17. LAMBDA EXPRESSIONS  Small functions can be created with the lambda keyword also known as Anonymous function.  Used wherever functions object are required.  These functions are called anonymous because they are not declared in the standard manner by using the def keyword. .  Syntax :  EXAMPLE: lambda [arg1 [,arg2,.....argn]]:expression Output:  The function returns the multiply of two arguments.  Lambda function is restricted to a single expressions.
  • 18. FUNCTION ANNOTATIONS  Function annotations are completely optional metadata information about the types used by user-defined functions.  Annotations are stored in the “__annotations__” attribute .  Parameter annotations are defined by a colon after the parameter name, followed by an expression evaluating to the value of the annotation.  Return annotations are defined by a literal ->, followed by an expression, between the parameter list and the colon denoting the end of the def statement.  Example: Output: Literal ‘->’ is used to define return annotations.
  • 19. DOCUMENTATION STRINGS  The first line should always be a short, concise summary of the object’s purpose.  The first line should begin with a capital letter and end with a period.  If there are more lines in the documentation string, the second line should be blank.  The first non-blank line after the first line of the string determines the amount of indentation for the entire documentation string.  Example: Output: ‘.doc’ is used to print the documentation strings.
  翻译: