Functions in Python:

A set of statements that does some computation and provides output is known as a function. The tasks that we have to frequently perform are made into a function. This is done in order to call the function when we need it instead of writing the long codes repeatedly for different inputs. There are some in-built functions in Python for Data Science. But we can create our own functions, such functions are known as user-defined functions.

Pass by reference/ Pass by value:

In python, we should remember that all variable names are a reference. When a variable is pass to the function, a new reference to the object will be created.

When a reference is passed, and then the reference receive is changed, the connection prevailing between the pass and receive parameters is broken. Let’s look at the below program to understand it properly.

Let us look into another example:

Default Arguments:

It is a parameter that assumes a default value if no value is provided in the function call for the respective argument.

Note:- In case we have a default value then, all argument values to its right should also be default in nature.

Keyword Arguments:

It is there to allow the caller for specifying argument name with values so that there is no need of remembering the order of the parameters.

python data science code

Variable Length Arguments:

There is the availability of both normal and keyword variable number of arguments is there.

python for data science

Anonymous Functions:

A nameless function is known as an anonymous function in Python. The keyword lambda is there for the creation of an anonymous function.

python data science

To learn more about python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.