SlideShare a Scribd company logo
amitu.com
Function arguments:
positional and keyword
Excerpt from Python For Programmers
amitu.com Descriptors In Python
This is from a section in my “Python for
Developers” book. The book covers python
material for people who are already
developers, even python developers.
Check it out: amitu.com/python/
amitu.com Descriptors In Python
In this we are going to learn about function
arguments in Python
Positional and Keyword arguments, *
and ** syntax etc.
amitu.com Function arguments: positional and keyword
Functions can take arguments when called.
Here we have defined a function foo, that takes
a single “positional argument”, x.
When we called foo(12), 12 got assigned to x
when the control was inside foo().
amitu.com Function arguments: positional and keyword
We can have more than one arguments:
So far so good.
amitu.com Function arguments: positional and keyword
One problem with function taking many arguments
is remembering the order of arguments.
amitu.com Function arguments: positional and keyword
Knowing that a function add_user() exists is not
enough, nor is knowing that it takes name, gender
and location. You must also remember in what order
those three must be supplied.
How do we make such obviously wrong code
look wrong?
amitu.com Function arguments: positional and keyword
Sometimes your code editor can help you. But we
can not always rely on that. What if you are
browsing code on GitHub?
amitu.com Function arguments: positional and keyword
To solve this precise problem, Python
supports function calling using what is called
“keyword argument” syntax:
… as against “positional arguments”, eg
foo(10, 20), where arguments are identified by
their position.
amitu.com Function arguments: positional and keyword
When using keyword arguments, you can even
change the order of keyword arguments, and
python will do the right thing.
amitu.com Function arguments: positional and keyword
We can also mix both positional and
keyword arguments:
isn't Python cool?
amitu.com Function arguments: positional and keyword
There is one constraint—we can not pass a
positional argument after a keyword argument. If we
use both, all positional arguments must come before
any keyword argument.
amitu.com Function arguments: positional and keyword
Default Values
Next:
amitu.com Function arguments: positional and keyword
In Python, we can define functions with
arguments that take default values.
amitu.com Function arguments: positional and keyword
We defined foo() to have default value of
10 for y. If we don't pass anything for y,
python uses the default value.
amitu.com Function arguments: positional and keyword
Only y has a default value, x is still a
required argument.
amitu.com Function arguments: positional and keyword
We can still use keyword arguments:
Or a mixed arguments:
amitu.com Function arguments: positional and keyword
NOTE: like we can not pass keyword arguments after
positional arguments when calling function, we
similarly cannot define functions with default values
before arguments that do not have default values.
Arguments with default values must come at the end.
amitu.com Function arguments: positional and keyword
Mutable default value
gotcha
amitu.com Function arguments: positional and keyword
One common gotcha when using default arguments is
using a mutable type as the default value.
Default value for users here is a list, [ ], which is a
mutable data type in Python.
amitu.com Function arguments: positional and keyword
Let us say our intention is to create a users list. If it is
not passed we want to use an empty list by default. We
append to passed list, or the default empty list, and
returned the modified list.
amitu.com Function arguments: positional and keyword
So far, so good, and it seems to be working fine.
Let us see when and where the problem begins.
What happened here? Why is “sam” in the
free_users list? add_user() should have taken
default empty list, and added “richard” and
returned that. Why two members?
amitu.com Function arguments: positional and keyword
What is happening is that, the empty list we have used
as default value of users in the function definition…
… the same instance is used as value of users,
every time we do not pass the second parameter.
And by the second time function is called,
the list is not empty any more!
amitu.com Function arguments: positional and keyword
The proper way to write such a function would
be using a value that would never make sense
to be passed, say None or -1.
ASIDE: such use of a value that is used for a
special purpose is called a sentinel value.
amitu.com Function arguments: positional and keyword
There is another subtle mistake we can make.
Let us look at another version of add_user() to
give emphasis to it.
Here, we first check if the passed in value is None.
We have used strong identity check (is None).
amitu.com Function arguments: positional and keyword
The difference is subtle users is None vs not users.
First creates a new list if nothing was passed (and we took
the default value of None), other if empty list was passed.
amitu.com Function arguments: positional and keyword
Yet another more reliable way to create
sentinel values is:
amitu.com Function arguments: positional and keyword
The reason such NotPassed is preferable over None
is because our code can have None assigned to
something by mistake, but getting NotPassed
assigned to some variable has to be intentional.
amitu.com Function arguments: positional and keyword
Variable Arguments
Sometimes we want to write functions that
take variable number of arguments.
amitu.com Function arguments: positional and keyword
This is how we write a function in Python that
takes variable number of arguments:
amitu.com Function arguments: positional and keyword
Note the *args. The * indicates to Python
that this function takes the variable number
of positional arguments, and when the
function is called, all those arguments are
stored in tuple() and passed to the function
by the name args. Instead of args, we could
have called it anything.
amitu.com Function arguments: positional and keyword
We can not treat args as a keyword argument.
But we can achieve the same by * syntax:
amitu.com Function arguments: positional and keyword
We have used * while calling the function. When
using this syntax, we must pass an iterable. It
can be a tuple, a list, or any iterable.
Note that the list was converted to a tuple.
Whatever you pass will get converted to tuple.
amitu.com Function arguments: positional and keyword
We can use this syntax even for functions that do
not take a variable number of arguments…
amitu.com Function arguments: positional and keyword
… as long as the number of items we pass is correct.
amitu.com Function arguments: positional and keyword
You can also mix variable arguments with
positional arguments.
amitu.com Function arguments: positional and keyword
Remember that we can not pass positional
arguments after keyword arguments.
amitu.com Function arguments: positional and keyword
In Python 2, this would not be valid:
amitu.com Function arguments: positional and keyword
Python 3 accepts it, but treats y as a compulsory
keyword argument.
amitu.com Function arguments: positional and keyword
A variable number of arguments works with default
value arguments too.
… both in Python 2 and Python 3.
amitu.com Function arguments: positional and keyword
But there is a possibility of ambiguity here.
Python would not accept it.
amitu.com Function arguments: positional and keyword
Like we have *arg syntax which tells Python to
capture all remaining positional arguments,
there is a similar **kw syntax that tells Python
to capture all remaining keyword arguments
even ones we never defined.
amitu.com Function arguments: positional and keyword
Python will capture all the keyword
arguments in a dict(), so everything that we
know about dict() can be used with them.
amitu.com Function arguments: positional and keyword
A new dictionary is constructed for you every
time a function that takes variable number of
keyword arguments is called.
amitu.com Function arguments: positional and keyword
In this case, our function accepts no
positional argument, so we can not call it
with a positional argument.
amitu.com Function arguments: positional and keyword
You can mix and match all forms of
arguments in a single function.
Just be careful that keyword arguments must come after
positional ones, and there must not be any ambiguities.
amitu.com Function arguments: positional and keyword
Finally, you can use the **{} syntax when
calling a function too.
Even when the function being called doesn't
take keyword arguments…
amitu.com Function arguments: positional and keyword
With these features, we can create a "universal
function" that can be called with any combination of
positional and keyword arguments:
These play special role when we are writing generic
decorators, or when we want to override a method
without knowing the parent methods signature.
amitu.com Descriptors In Python
Thats it for now!
You have seen a section in my “Python for
Developers” book. The book covers
python material for people who're already
developers, even python developers.
Check it out: amitu.com/python/

More Related Content

What's hot (20)

PPT
Python Pandas
Sunil OS
 
PDF
Python list
Mohammed Sikander
 
PDF
Python tuple
Mohammed Sikander
 
PPSX
Modules and packages in python
TMARAGATHAM
 
PPTX
List in Python
Sharath Ankrajegowda
 
PDF
Python programming : List and tuples
Emertxe Information Technologies Pvt Ltd
 
PPTX
Python-Functions.pptx
Karudaiyar Ganapathy
 
PPTX
Packages In Python Tutorial
Simplilearn
 
PPTX
Regular expressions in Python
Sujith Kumar
 
PPT
Python GUI Programming
RTS Tech
 
PPSX
Programming with Python
Rasan Samarasinghe
 
PPTX
Strings in C
Kamal Acharya
 
PPTX
Strings in C language
P M Patil
 
PPTX
Queues
Ashim Lamichhane
 
PDF
Python-03| Data types
Mohd Sajjad
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
C++ string
Dheenadayalan18
 
PDF
Python programming : Standard Input and Output
Emertxe Information Technologies Pvt Ltd
 
PPTX
Functions in Python
Kamal Acharya
 
Python Pandas
Sunil OS
 
Python list
Mohammed Sikander
 
Python tuple
Mohammed Sikander
 
Modules and packages in python
TMARAGATHAM
 
List in Python
Sharath Ankrajegowda
 
Python programming : List and tuples
Emertxe Information Technologies Pvt Ltd
 
Python-Functions.pptx
Karudaiyar Ganapathy
 
Packages In Python Tutorial
Simplilearn
 
Regular expressions in Python
Sujith Kumar
 
Python GUI Programming
RTS Tech
 
Programming with Python
Rasan Samarasinghe
 
Strings in C
Kamal Acharya
 
Strings in C language
P M Patil
 
Python-03| Data types
Mohd Sajjad
 
Python Functions
Mohammed Sikander
 
C++ string
Dheenadayalan18
 
Python programming : Standard Input and Output
Emertxe Information Technologies Pvt Ltd
 
Functions in Python
Kamal Acharya
 

Viewers also liked (20)

PPSX
python Function
Ronak Rathi
 
PDF
Coverfox: Tech Productivity etc
Amit Upadhyay
 
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
 
PDF
Lazy evaluation in Python
Rahul Pydimukkala
 
PDF
Python testing-frameworks overview
Jachym Cepicky
 
PPTX
Python datatype
건희 김
 
PDF
4. python functions
in4400
 
ODP
Python Modules
Nitin Reddy Katkam
 
PDF
Functions in python
Ilian Iliev
 
PPTX
Taking care of your computers
Jean Ulpindo
 
PDF
Python for All
Pragya Goyal
 
PDF
Ansible loves Python, Python Philadelphia meetup
Greg DeKoenigsberg
 
PPTX
Advance OOP concepts in Python
Sujith Kumar
 
PPTX
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Sian Lerk Lau
 
PPTX
Basics of Object Oriented Programming in Python
Sujith Kumar
 
python Function
Ronak Rathi
 
Coverfox: Tech Productivity etc
Amit Upadhyay
 
Descriptors In Python
Amit Upadhyay
 
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Input and Output
Marieswaran Ramasamy
 
Lazy evaluation in Python
Rahul Pydimukkala
 
Python testing-frameworks overview
Jachym Cepicky
 
Python datatype
건희 김
 
4. python functions
in4400
 
Python Modules
Nitin Reddy Katkam
 
Functions in python
Ilian Iliev
 
Taking care of your computers
Jean Ulpindo
 
Python for All
Pragya Goyal
 
Ansible loves Python, Python Philadelphia meetup
Greg DeKoenigsberg
 
Advance OOP concepts in Python
Sujith Kumar
 
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Sian Lerk Lau
 
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Ad

Similar to Function arguments In Python (20)

PPTX
Functions in Python with all type of arguments
riazahamed37
 
PDF
Python Programming - Functions and Modules
Omid AmirGhiasvand
 
PDF
beginners_python_cheat_sheet_pcc_functions.pdf
GuarachandarChand
 
PDF
functionnotes.pdf
AXL Computer Academy
 
PPTX
Lecture 08.pptx
Mohammad Hassan
 
PPTX
Functions2.pptx
AkhilTyagi42
 
PPTX
_Python_ Functions _and_ Libraries_.pptx
yaramahsoob
 
PDF
Functionscs12 ppt.pdf
RiteshKumarPradhan1
 
PDF
Functions.pdf
kailashGusain3
 
PDF
Functions_21_22.pdf
paijitk
 
PDF
Functions.pdf cbse board latest 2023-24 all covered
anuragmaji08
 
PDF
Userdefined functions brief explaination.pdf
DeeptiMalhotra19
 
PPT
functions _
SwatiHans10
 
PPTX
Function in Python function in python.pptx
JHILIPASAYAT
 
PDF
Functions2.pdf
Daddy84
 
PPTX
UNIT 3 python.pptx
TKSanthoshRao
 
PPTX
Functions in python slide share
Devashish Kumar
 
PPTX
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
Osama Ghandour Geris
 
PPTX
Chapter 2 Python Functions
11210208
 
PDF
Unit_2.0_Functions (1).pdfUnit_2.0_Functions (1).pdf
RutviBaraiya
 
Functions in Python with all type of arguments
riazahamed37
 
Python Programming - Functions and Modules
Omid AmirGhiasvand
 
beginners_python_cheat_sheet_pcc_functions.pdf
GuarachandarChand
 
functionnotes.pdf
AXL Computer Academy
 
Lecture 08.pptx
Mohammad Hassan
 
Functions2.pptx
AkhilTyagi42
 
_Python_ Functions _and_ Libraries_.pptx
yaramahsoob
 
Functionscs12 ppt.pdf
RiteshKumarPradhan1
 
Functions.pdf
kailashGusain3
 
Functions_21_22.pdf
paijitk
 
Functions.pdf cbse board latest 2023-24 all covered
anuragmaji08
 
Userdefined functions brief explaination.pdf
DeeptiMalhotra19
 
functions _
SwatiHans10
 
Function in Python function in python.pptx
JHILIPASAYAT
 
Functions2.pdf
Daddy84
 
UNIT 3 python.pptx
TKSanthoshRao
 
Functions in python slide share
Devashish Kumar
 
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
Osama Ghandour Geris
 
Chapter 2 Python Functions
11210208
 
Unit_2.0_Functions (1).pdfUnit_2.0_Functions (1).pdf
RutviBaraiya
 
Ad

Recently uploaded (20)

PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
Deploy Faster, Run Smarter: Learn Containers with QNAP
QNAP Marketing
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
FME in Overdrive: Unleashing the Power of Parallel Processing
Safe Software
 
PDF
Sound the Alarm: Detection and Response
VICTOR MAESTRE RAMIREZ
 
PDF
Draugnet: Anonymous Threat Reporting for a World on Fire
treyka
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Deploy Faster, Run Smarter: Learn Containers with QNAP
QNAP Marketing
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
FME in Overdrive: Unleashing the Power of Parallel Processing
Safe Software
 
Sound the Alarm: Detection and Response
VICTOR MAESTRE RAMIREZ
 
Draugnet: Anonymous Threat Reporting for a World on Fire
treyka
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 

Function arguments In Python

  • 1. amitu.com Function arguments: positional and keyword Excerpt from Python For Programmers
  • 2. amitu.com Descriptors In Python This is from a section in my “Python for Developers” book. The book covers python material for people who are already developers, even python developers. Check it out: amitu.com/python/
  • 3. amitu.com Descriptors In Python In this we are going to learn about function arguments in Python Positional and Keyword arguments, * and ** syntax etc.
  • 4. amitu.com Function arguments: positional and keyword Functions can take arguments when called. Here we have defined a function foo, that takes a single “positional argument”, x. When we called foo(12), 12 got assigned to x when the control was inside foo().
  • 5. amitu.com Function arguments: positional and keyword We can have more than one arguments: So far so good.
  • 6. amitu.com Function arguments: positional and keyword One problem with function taking many arguments is remembering the order of arguments.
  • 7. amitu.com Function arguments: positional and keyword Knowing that a function add_user() exists is not enough, nor is knowing that it takes name, gender and location. You must also remember in what order those three must be supplied. How do we make such obviously wrong code look wrong?
  • 8. amitu.com Function arguments: positional and keyword Sometimes your code editor can help you. But we can not always rely on that. What if you are browsing code on GitHub?
  • 9. amitu.com Function arguments: positional and keyword To solve this precise problem, Python supports function calling using what is called “keyword argument” syntax: … as against “positional arguments”, eg foo(10, 20), where arguments are identified by their position.
  • 10. amitu.com Function arguments: positional and keyword When using keyword arguments, you can even change the order of keyword arguments, and python will do the right thing.
  • 11. amitu.com Function arguments: positional and keyword We can also mix both positional and keyword arguments: isn't Python cool?
  • 12. amitu.com Function arguments: positional and keyword There is one constraint—we can not pass a positional argument after a keyword argument. If we use both, all positional arguments must come before any keyword argument.
  • 13. amitu.com Function arguments: positional and keyword Default Values Next:
  • 14. amitu.com Function arguments: positional and keyword In Python, we can define functions with arguments that take default values.
  • 15. amitu.com Function arguments: positional and keyword We defined foo() to have default value of 10 for y. If we don't pass anything for y, python uses the default value.
  • 16. amitu.com Function arguments: positional and keyword Only y has a default value, x is still a required argument.
  • 17. amitu.com Function arguments: positional and keyword We can still use keyword arguments: Or a mixed arguments:
  • 18. amitu.com Function arguments: positional and keyword NOTE: like we can not pass keyword arguments after positional arguments when calling function, we similarly cannot define functions with default values before arguments that do not have default values. Arguments with default values must come at the end.
  • 19. amitu.com Function arguments: positional and keyword Mutable default value gotcha
  • 20. amitu.com Function arguments: positional and keyword One common gotcha when using default arguments is using a mutable type as the default value. Default value for users here is a list, [ ], which is a mutable data type in Python.
  • 21. amitu.com Function arguments: positional and keyword Let us say our intention is to create a users list. If it is not passed we want to use an empty list by default. We append to passed list, or the default empty list, and returned the modified list.
  • 22. amitu.com Function arguments: positional and keyword So far, so good, and it seems to be working fine. Let us see when and where the problem begins. What happened here? Why is “sam” in the free_users list? add_user() should have taken default empty list, and added “richard” and returned that. Why two members?
  • 23. amitu.com Function arguments: positional and keyword What is happening is that, the empty list we have used as default value of users in the function definition… … the same instance is used as value of users, every time we do not pass the second parameter. And by the second time function is called, the list is not empty any more!
  • 24. amitu.com Function arguments: positional and keyword The proper way to write such a function would be using a value that would never make sense to be passed, say None or -1. ASIDE: such use of a value that is used for a special purpose is called a sentinel value.
  • 25. amitu.com Function arguments: positional and keyword There is another subtle mistake we can make. Let us look at another version of add_user() to give emphasis to it. Here, we first check if the passed in value is None. We have used strong identity check (is None).
  • 26. amitu.com Function arguments: positional and keyword The difference is subtle users is None vs not users. First creates a new list if nothing was passed (and we took the default value of None), other if empty list was passed.
  • 27. amitu.com Function arguments: positional and keyword Yet another more reliable way to create sentinel values is:
  • 28. amitu.com Function arguments: positional and keyword The reason such NotPassed is preferable over None is because our code can have None assigned to something by mistake, but getting NotPassed assigned to some variable has to be intentional.
  • 29. amitu.com Function arguments: positional and keyword Variable Arguments Sometimes we want to write functions that take variable number of arguments.
  • 30. amitu.com Function arguments: positional and keyword This is how we write a function in Python that takes variable number of arguments:
  • 31. amitu.com Function arguments: positional and keyword Note the *args. The * indicates to Python that this function takes the variable number of positional arguments, and when the function is called, all those arguments are stored in tuple() and passed to the function by the name args. Instead of args, we could have called it anything.
  • 32. amitu.com Function arguments: positional and keyword We can not treat args as a keyword argument. But we can achieve the same by * syntax:
  • 33. amitu.com Function arguments: positional and keyword We have used * while calling the function. When using this syntax, we must pass an iterable. It can be a tuple, a list, or any iterable. Note that the list was converted to a tuple. Whatever you pass will get converted to tuple.
  • 34. amitu.com Function arguments: positional and keyword We can use this syntax even for functions that do not take a variable number of arguments…
  • 35. amitu.com Function arguments: positional and keyword … as long as the number of items we pass is correct.
  • 36. amitu.com Function arguments: positional and keyword You can also mix variable arguments with positional arguments.
  • 37. amitu.com Function arguments: positional and keyword Remember that we can not pass positional arguments after keyword arguments.
  • 38. amitu.com Function arguments: positional and keyword In Python 2, this would not be valid:
  • 39. amitu.com Function arguments: positional and keyword Python 3 accepts it, but treats y as a compulsory keyword argument.
  • 40. amitu.com Function arguments: positional and keyword A variable number of arguments works with default value arguments too. … both in Python 2 and Python 3.
  • 41. amitu.com Function arguments: positional and keyword But there is a possibility of ambiguity here. Python would not accept it.
  • 42. amitu.com Function arguments: positional and keyword Like we have *arg syntax which tells Python to capture all remaining positional arguments, there is a similar **kw syntax that tells Python to capture all remaining keyword arguments even ones we never defined.
  • 43. amitu.com Function arguments: positional and keyword Python will capture all the keyword arguments in a dict(), so everything that we know about dict() can be used with them.
  • 44. amitu.com Function arguments: positional and keyword A new dictionary is constructed for you every time a function that takes variable number of keyword arguments is called.
  • 45. amitu.com Function arguments: positional and keyword In this case, our function accepts no positional argument, so we can not call it with a positional argument.
  • 46. amitu.com Function arguments: positional and keyword You can mix and match all forms of arguments in a single function. Just be careful that keyword arguments must come after positional ones, and there must not be any ambiguities.
  • 47. amitu.com Function arguments: positional and keyword Finally, you can use the **{} syntax when calling a function too. Even when the function being called doesn't take keyword arguments…
  • 48. amitu.com Function arguments: positional and keyword With these features, we can create a "universal function" that can be called with any combination of positional and keyword arguments: These play special role when we are writing generic decorators, or when we want to override a method without knowing the parent methods signature.
  • 49. amitu.com Descriptors In Python Thats it for now! You have seen a section in my “Python for Developers” book. The book covers python material for people who're already developers, even python developers. Check it out: amitu.com/python/