Functions Flashcards

1
Q

Creating Functions

A

Allows you to give a set of instructions a name, so you can trigger it multiple times without having to re-write or copy-paste it.

The contents of the function must be indented to signal that it’s inside.

def my_function():
print(“Hello”)
name = input(“Your name:”)
print(“Hello”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Calling Functions

A

You activate a function by calling it.

This is done by writing the name of the function followed by set of round brackets, also allowing you to trigger how many times.

my_function()
my_function()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Functions with Inputs

A

You can give the function an input, this way the function can do something different depending on the input.

def add(n1, n2):
print (n1 + n2)
add(2, 3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Functions with Outputs

A

In addition to Inputs, a function can also have an output. The output value is proceeded by the keyword “return”.

This allows you to store the result from a function.

def add(n1, n2):
return n1 + n2

result = add(2, 3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly