Creating functions in Python

In the last post you saw how to call functions. But how to create them?

It’s pretty straightforward you simply have to tell the compiler the name of the function and the parameters. It looks like this for a simple multiplication function:

The name is “mult_function” and the parameters are “a,b”. We tell the compiler to multiply them.

Keep one thing in mind: You can’t have two functions with the same name. Think of it like a rehearsed play which is given a name which the coach screams when it is time to play it. Wouldn’t it be super confusing to take the same names for different plays? Nobody knew what to do then. Neither would Python do (= no function overloading), but it solves this dilemma by only using the latest defined function.

You can do a lot with functions. For example you can calculate Fahrenheit to Celcius as I did it here:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s