
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Keyword arguments in Python
Keyword arguments are related to the function calls. When you use keyword arguments in a function call, the caller identifies the arguments by the parameter name.
This allows you to skip arguments or place them out of order because the Python interpreter is able to use the keywords provided to match the values with parameters. You can also make keyword calls to the printme() function in the following ways −
Example
#!/usr/bin/python # Function definition is here def printme( str ): "This prints a passed string into this function" print str return; # Now you can call printme function printme( str = "My string")
Output
When the above code is executed, it produces the following result −
My string
The following example gives more clear picture. Note that the order of parameters does not matter.
Example
#!/usr/bin/python # Function definition is here def printinfo( name, age ): "This prints a passed info into this function" print "Name: ", name print "Age ", age return; # Now you can call printinfo function printinfo( age=50, name="miki" )
Output
When the above code is executed, it produces the following result −
Name: miki Age 50
- Related Articles
- Python Pandas - Display the keyword arguments applied on the given BusinessDay object
- Python Pandas - Display the keyword arguments applied on the given BusinessHour object
- Python Pandas - Display the keyword arguments applied on the given CustomBusinessDay object
- Python Pandas - Display the keyword arguments applied on the given CustomBusinessHour object
- Required arguments in Python
- Default arguments in Python
- Command Line Arguments in Python
- Variable-length arguments in Python
- Global keyword in Python
- Finally keyword in Python
- assert keyword in Python
- Packing and Unpacking Arguments in Python?
- What are default arguments in python?
- Global keyword in Python program
- Command Line and Variable Arguments in Python?

Advertisements