Functions Flashcards
To begin grouping related code, we start defining a function with the keyword…
def
How do you build the beginning of a function?
def
then the function’s name in snake case
Followed by parentheses
Then :
def greet_user():
How do we call a function?
We call a function by coding it’s name followed by parentheses like greet_user()
How do we start grouping related code?
by adding the def keyword
How do we name a function?
Using snake case
What does the colon : do?
They mark the beginning of a function’s code block
Where does the code we want to group together go?
After the function definition, indented by two spaces
How do we run the code inside a function?
By calling it with it’s name and ()
How do we pass a value to a function?
By adding a variable called a parameter inside the parentheses of the function.
def greet(name)
In this example, name is the variable called a parameter.
Why do we pass specific values to functions?
So we can use the same code for different values
Where do parameters go?
Parameters go inside the parentheses of the function we’re creating
What does a parameter do?
It is a variable that passes a value to a function
How do we pass a value to the function’s parameter?
We call the function with the value between parentheses.
To return something from a function we add what keyword?
Return
What types of values can functions return?
Any type like string, integer, float or boolean.