Creating Python functions

To create a function you have to give your function a name after the word “def” and then, in parenthesis, specify the variable you’re going to work with within that function. After that, you want to write what you want the program to do in return whenever you call that function. For example:

def hello(x):

       return “Hey there ” + x

And there you go. You’ve created a new function!

CC BY 4.0 Creating Python functions by Jorge Padilla is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.