Sitemap
Python in Plain English

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

Member-only story

Python Functions For Everyone (Well Explained)

--

Press enter or click to view image in full size
Photo by Hitesh Choudhary on Unsplash

This post is a part of my Python 101 series for total beginners (read here the previous post about Python Loops).

Let’s talk about functions…

Functions are nothing more than lines of code that you give a certain name so that you can call them later when you need them. This way, you can organize your code better so that the code is easier to read and understand.

When you create a function, you must define its name and the possible parameters that the function takes. Let’s immediately write a very simple function.

Click here to run this code — press the green “Run” button once there

def greetings(): # Defines a new function
print("This is my first function!")
greetings()   # Calls the function

We defined our function by using the def keyword followed by the function name and the brackets (). In the body of the function, we have the line that prints This is my first function!.

--

--

Igor Jovanovic M.Sc.
Igor Jovanovic M.Sc.

Written by Igor Jovanovic M.Sc.

🔥12 Mil+ Views |⌨️Professional Coder/Architect |🌙Marketer & Copywriter At Night |💲Six-fig Tech Career |💁‍♂️Learn From Me: https://linktr.ee/ij_consultancy

Python in Plain English
Python in Plain English

Published in Python in Plain English

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