Making Functions with Python

GuyinGreen
1 min readApr 27, 2024

--

Python can be easy but the hardest part for most people can be Functions. Functions are what make up Python. Without functions, we can do anything except for defining variables.

There are some built-in functions and Custom Functions.

Some Functions run Code and Some return text, numbers, or a bool. We Will look into Built-in Functions in a different lesson because this is going to be for Making Custom Functions.

First, we define our function. Let’s call it my function.

def myFunction(a,b):

then we’re going to insert return to return a value.

def myFunction(a,b):
return

Then We’re going to put a custom value in there.

def myFunction(a,b):
return 4

Then Print that value by making a new variable,

def myFunction(a,b):
return 4

output = myFunction(4,5)

Then Printing it.

def myFunction(a,b):
return 4

output = myFunction(4,5)
print(output)

Then we can change the returning value based on A and B.

def myFunction(a,b):
return ((a*b)-a/(b)*2)*(a/b)*4

output = myFunction(4,5)
print(output)

Then it returns a custom value.

It returns 58.879

If you like this consider subscribing and Following.

BYE!

--

--

GuyinGreen

I'm a C++ and Python Developer hope you Subscribe and Learn!