 Call Kai
Call Kai Learn
Learn Practice Test
Practice Test Spaced Repetition
Spaced Repetition Match
Match1/25
Looks like no tags are added yet.
| Name | Mastery | Learn | Test | Matching | Spaced | 
|---|
No study sessions yet.
function
A reusable block of code that performs a specific task.
def function_name(parameters):
How to define a function.
return
The keyword used to exit a function and send a value back.
parameter
A variable listed inside parentheses in a function definition.
argument
The actual value passed into a function when it's called.
return None
Indicates the function has no explicit return value.
scope of a variable
Local — it exists only inside that function.
mutable arguments
Changes inside the function affect the original object.
immutable arguments
They do not change the original variable.
function call vs definition
A definition creates it; a call executes it.
function call
function_name(arguments)
return multiple values
Return them as a tuple → return a, b, c
capture multiple return values
x, y, z = function()
docstring
To describe what a function does (written as """Description""").
two functions with the same name
The later one overwrites the earlier.
modify a global variable
Only if declared with global var_name.
better practice than modifying globals
Pass values in and return results instead.
top-down design
Breaking a program into smaller, manageable functions.
why use functions
Reusability, readability, debugging simplicity.
printing vs returning
Printing displays output; returning makes data reusable.
default values for parameters
def func(x, y = 10):
call a function without required arguments
It raises a TypeError.
pass expressions as arguments
Yes — they're evaluated before the call.
comment inside functions
Use # for single-line comments.
placeholder function
pass
returning early from a function
Using return inside an if to exit early based on a condition.