Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Positional vs Keyword Arguments in Python

Where, when, and how to use positional and keyword arguments in python.

John Philip
Python in Plain English
4 min readSep 21, 2021

--

Photo by David Clode on Unsplash

Python functions consist of two main types of arguments that are either positional or keyword arguments.

Arguments and parameters are always confused with a lot of people. So let us see what an argument and parameter is.

Parameter — A parameter is a variable in a method definition or function.

Arguments — Arguments are the data or values that are passed into the function or method call. Arguments are provided when a function is called.

Simple illustration of Parameters and Arguments.

Functions in python at times may require you to declare functions that take in some parameters to solve some problems of returning some values.

Especially when we want to declare reusable functions in python, arguments come in handy when we want to call the function in various occurrences with varying values.

Take for instance the code snippet above, we have declared a function that takes in the parameter “name” and prints some message to the user.

We then call the function and providing it with an argument. So, when the function is called, the function will print a message to us.

Positional Arguments.

Positional arguments are arguments that can be called by their position in the function definition. In the case above, we are providing the positional argument.

From our code snippet above, we have the user_message function that takes in two parameters Name and age. From this functional call, we have two positional arguments that should be…

--

--

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Written by John Philip

Dev | Life Café | Twitter at @amjohnphilip | Email: dxphilo@gmail.com

No responses yet

Write a response