Functions and Arguments


A function is a chunk of code that can receive data and return it.To create a function we use the def keyword for example:

Input:

def my_function():
  print("Hello World")

my_function()

Output:

Hello World

Arguments are information that are specified after the function name for example:

Input:

def my_function(name):
  print("my name is" +  name)

myfunction("Bob")

myfunction("Bill")

myfunction("Joe")

myfunction("Moe")

Output:

my name is Bob

my name is Bill

my name is Joe

my name is Moe

You can also create a list as an argument for example:

Input:

def my_function(drinks):
  for x in food:
    print(x)

caffeine= ["coke""tea""coffee"]

my_function(caffeine)

Output:

coke

tea

coffee

Leave a comment

Log in with itch.io to leave a comment.