+ INFORMATION

Share on social networks!

My First Function in Python

A few weeks ago we talked to you about the Predefined functions in Python, are those that they come integrated and they help us list, add, print on the screen, etc.

But sometimes we're going to need a function to do something specific outside of the predefined ones and we will have to create it ourselves, so let's see how it is done.

Remember that you can continue learning about programming, in  EIP with our master in Advanced Programming in Python for Big Data, Hacking and Machine Learning.

Create a function in Python

To create a function we start from the instruction def, Let us remember that this word is included within the Keywords of Python, followed by the name of the function and ending it with a colon ' : '.

my first function in python

For example, we are going to make our first function print the typical "Hello World"

first function with python

First we define in the function a print with Hello World and then we invoke it to print the message, remember that if the function is not called it will never do anything.

We can also make that function return a data to later assign it to some variable.

my first function programming with python

Finally, so as not to extend ourselves, we are going to see the functions with parameters, these functions receive parameters that we have previously defined to execute the corresponding code.

function with python

The parameters that our function receives can be any type of data, numbers, letters, lists, etc. But we will see that another time.

Next week we will use what we learned to update our Calculator in Python and make it a little more efficient.

Subscribe to our newsletter to stay up to date with all the news

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SA as the person responsible for this website. The purpose of collecting and processing personal data is to respond to the query made as well as to send information about the services of the data controller. Legitimation is the consent of the interested party.
You can exercise your rights of access, rectification, limitation and deletion of data in compliance@grupomainjobs.com as well as the right to file a claim with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find in our Web page
marter-in-python

Leave a comment