Glossary

This glossary defines key Python terms used in this course. You can also consult the Python Glossary for the official definitions.

General

Mutable
A data value that can be changed after created. Lists and dictionaries are both mutable (i.e. you can append to a list or change the value of a key in a dictionary).
names = ['Pamela', 'Amber']
names.append('Tommy')
Immutable
A data value that cannot be changed after created, like a number or a string. Attempting to do so results in a runtime error. Example:
name = 'pamela'
name[0] = 'P'  # Error!
Sequence
A data type in Python that supports sequence operations. Strings and lists are both sequences.
Method
A function that is called on an object, using dot notation.
fruits = ['apples', 'bananas']
fruits.append('watermelon')  # append is a method
len(fruits)                  # len() is a function

Functions

Function
A reusable block of code that takes in certain parameters and returns a value.
Function definition
The code that defines a function, starting with the function signature and containing the function body. A function definition only makes that function exist in memory, it does not call the function.
def add(num1, num2):
    result = num1 + num2
    return result
Function signature/header
The first line of the function that has the name and parameters.
def add(num1, num2):
Function parameters
The names inside the parentheses of the function header. When a function is called, those names are set to the values passed in, and the function body can use the names to reference them.
num1, num2
Function body
Everything but the function header! - all the lines of code that are indented at least one level inside the def statement.
    result = num1 + num2
    return result
Function call
An expression that calls a function, i.e. that tells Python to actually run the code in the function body on a set of arguments.
add(3, 5)
Function arguments
The values that are passed in a function call. The number of arguments in a function call needs to map the number of parameters in the function signature.
3, 5

Logic

Boolean value
A value that is either true or false. Written True and False in Python.
Boolean expression
An expression that evaluates to either true or false (or truthy/falsy), using a combination of comparison operators (>, <, ==, etc) or logical operators (and/or/not).
Conditional
A statement that uses if to determine whether to execute a block of code. Can optionally use elif for additional conditions, and else for fallback code.
Truthy
Whether a value is consider true when its inside a Boolean context (like an if). Python considers the following to be truthy: non-0 numbers, non-empty strings, non-empty lists, True. The following conditions are all considered truthy:
if "yes":
if [1, 2, 3]:
if 10:
Falsey
Whether a value is consider false when its inside a Boolean context (like an if). Python considers the following to be falsey: 0, 0.0, empty strings, empty lists, False. The following conditions are all considered falsey:
if "":
if []:
if 0:

Loops

Loop
A way of repeating a block of code. Python has two kinds of loops, while and for.
While loop
A loop that repeats a block of code while a certain condition is true.
x = 0
while x < 10:
    x += 1
Loop condition
The Boolean expression used in the header of a while loop to decide whether the loop should keep going.
x < 10
For loop
A loop that calls the block of code for each item in a list/string/any iterable object.
numbers = [1, 2, 3]
for num in numbers:
    print(num * 2)
Iteration
One repetition of a loop. For example, you could say "on each iteration, the loop increments x by 1."
Iterate
(verb) Using a loop to repeatedly process items in a list/string/any iterable object. For example, "this for loop will iterate through each number in this list."
Iterable
(adjective) Any value that can be used with a for loop, like a list or string. Python has a few other iterable values which we'll learn later.
Counter variable
A variable that keeps track of the number of iterations of a loop. Typically used with while loops to makes sure we only loop a certain number of times. Often named counter!
counter = 0
while counter < 10:
    counter += 1

Lists

List
A mutable data type that stores an ordered sequence of data, with each item at a particular index in the sequence.
flavors = ['mint', 'chocolate', 'orange']
Index
The position of an item in a list. The first index is 0, the last index is 1 less than the length of the list.
flavors = ['mint', 'chocolate', 'orange']
# Index:     0         1          2
Zero-indexed
When lists in a language start with an index of 0. Python uses zero indexing. Other languages are one-indexed instead, where the first index is 1.
Bracket notation
Using square brackets to access elements of a list by specifying the index inside the brackets. Can also be used with the assignment operator to update elements.
flavors = ['mint', 'chocolate', 'orange']
print(flavors[0])  # 'mint'
flavors[0] = 'mint choco chip'

Strings

String
An immutable data type that stores an ordered sequence of characters.
"superduper"
Concatenation
Combining two strings together using the + operator.
String literal
A string value inside quotes, versus a variable that stores a string value or an expression that evaluates to a string.
"Literally a string"      # String literal
stored = "stored string"  # String-storing variable
("Bruno" + "no" * 3)      # Expression that evaluates to a string

Dictionaries

Dict(ionary)
A mutable data type that stores a mapping of keys to values.
{"CA": "California"}

OOP

Object
A bundle of data (instance variables) and functionality (methods). For example, a list is an object that bundles together data, a sequence of items, plus associated functionality, like appending.
Class
A template for defining new types of objects. A class definition looks like:
class Student:
    # class variables
    # methods
Instance
A particular object of a class. For example, this code constructs a new instance of the Student class:
pamela = Student("Pamela")
Instance variables
Data attributes that belong to a particular instance (object). Each instance has their own instance variables. Instance variables are typically initialized inside an __init__ method. For example, this class initializes two instance variables on each instance:
class Student:
    def __init__(self, name):
        self.name = name
        self.points = 0
        
pamela = Student("Pamela")
pamela.name   # "Pamela"
pamela.points # 0
Methods
Functions that can be called on a particular instance (object). Methods are defined in the class definition, and they typically access or change instance variables in some way. For example, this method increases an instance variable by a given amount.
class Student:
    def award_extra_credit(self, amount):
        self.points += amount
          
pamela = Student("Pamela")
pamela.points # 0
pamela.award_extra_credit(3)
pamela.points # 3
Class variables
Data attributes that are the same value across all instances of a particular class. For example, this Student class has a class variable of max_points:
class Student:
    max_points = 300
    
pamela = Student("Pamela")
hunter = Student("Hunter")
pamela.max_points # 300
hunter.max_points # 300