1/24
Vocabulary flashcards based on a lecture about functions in Python.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Function
A reusable block of code that performs a specific task.
Def
The keyword used to define a function in Python.
Call a Function
Using the function's name followed by parentheses () to execute it.
Parameter
A variable inside a function definition.
Argument
The actual value passed into a function.
Difference between Parameter and Argument
Parameter is a placeholder; Argument is the actual value.
Return Statement
Sends a value back and stops the function.
Effect of Return Statement
The function immediately stops executing after the return.
print() vs return
print() displays output; return gives back a value.
Positional Arguments
Arguments passed based on order (must match position).
Missing Required Positional Argument
Python throws an error if a required positional argument is missing.
Default Arguments
Parameters with preset values used if no argument is provided.
Rule for Default Arguments Order
Positional arguments must come before default ones.
Keyword Arguments
Arguments passed using parameter names where order doesn’t matter.
Order of Arguments in Function Call
Positional arguments come first, followed by keyword arguments.
*args
Represents multiple unnamed arguments, stored as a tuple/list.
**kwargs
Represents multiple named arguments, stored as a dictionary.
Scope
The range within which a variable exists and can be used.
Accessing Variables Outside Function
Variables inside a function cannot be accessed outside.
Mutable Data Type
A type that can be changed, such as lists and dictionaries.
Immutable Data Type
A type that cannot be changed, such as integers, strings, and tuples.
Passing Mutable Object into Function
It can be changed permanently.
Passing Immutable Object into Function
Changes do NOT affect the original.
Recursion
A function that calls itself.
Base Case in Recursion
A stopping condition required for recursion to work properly.