Topic 4 Flashcards
How would you write a custom function, that when called, would print the word ‘‘hello”?
def hello() print("Hello")
Why would you use a function in python?
It is used to group code that is used multiple times when called.
See the following code example.
def hello(name)
What is the proper term for “name” in context when using functions.
It is called a parameter.
When you call a function and pass a value into the function, what is the passed value called?
An argument.
Variables that exist inside of a function have what type of scope?
Local scope
Variables that exist outside of all functions have what type of scope?
Global scope
Can a variable be local and global scope?
No
If an assignment variable is assigned within a function, what scope does that variable have?
Example:
def spam(): eggs = 10 print(eggs)
A assignment statement within a function has local scope.
No assignment statement means it has global scope.