USD ($)
$
United States Dollar
Euro Member Countries
India Rupee
د.إ
United Arab Emirates dirham
ر.س
Saudi Arabia Riyal

Parameters and Return Values

Lesson 19/35 | Study Time: 60 Min

A function becomes truly powerful when it can receive data, process it, and send back a result. Parameters and return values are what make this possible.

Parameters allow you to pass information into a function, while return values allow the function to send a result back to the caller.

Together, they transform a simple block of code into a flexible, reusable tool, a concept that sits at the heart of clean, professional Python programming.

Parameters vs Arguments

These two terms are often confused but have a clear distinction:

Types of Parameters

Python offers several ways to define and pass parameters, giving you flexibility in how functions receive data.

Positional Parameters

The most common type, values are assigned to parameters in the order they are passed.


Order matters with positional parameters, always pass arguments in the correct sequence.

Keyword Arguments

You can pass arguments by explicitly naming the parameter. This removes the dependency on order.


Keyword arguments improve readability, especially in functions with many parameters.

Default Parameters

A parameter can have a default value that is used when no argument is provided for it.

Rule: Default parameters must always be placed after non-default parameters in the function definition.

Arbitrary Arguments — *args

When you do not know how many arguments will be passed, use *args. It collects all positional arguments into a tuple.



Arbitrary Keyword Arguments — **kwargs

Similarly, **kwargs collects any number of keyword arguments into a dictionary.

Return Values

The return statement sends a result from the function back to wherever it was called. Without return, a function performs an action but gives nothing back, it returns None by default.


The returned value can be stored in a variable, printed directly, or used in further calculations.


Returning Multiple Values

A Python function can return more than one value at once. The values are packed into a tuple automatically.


Early Return

A function can return at any point. Once return is reached, the function exits immediately, remaining code in the function is skipped.


Early returns are useful for handling edge cases and invalid inputs before the main logic runs.

Functions Without Return — None

If a function has no return statement, Python returns None automatically.


This is fine for functions that perform an action but do not need to send back a value.

Putting It All Together



Sales Campaign

Sales Campaign

We have a sales campaign on our promoted courses and products. You can purchase 1 products at a discounted price up to 15% discount.