1/65
Vocabulary flashcards covering core topics for Python Exam 3: collections (lists, strings, tuples, sets, dictionaries), file input/output, exceptions and common error types, and object-oriented programming concepts (classes, instances, methods, and operator overloading).
Python Indexing
Sequence indexing in Python always starts at position 0.
List
A built-in data type that is ordered, mutable, allows duplicate values, and is accessed by index (e.g., [1, 2, 3], indexed via a[0]).
String
A built-in data type that is ordered, not mutable (immutable), allows duplicates, and is accessed by index (e.g., "abc", indexed via s[0]).
Tuple
A built-in sequence that is ordered, not mutable (cannot be changed after creation), allows duplicates, and is indexed like a list (e.g., (1, 2, 3)).
Set
A collection that is unordered, mutable, contains no duplicates, and does not support indexing (elements are accessed using in or a loop; e.g., {1, 2, 3}).
Dictionary (dict)
A collection that keeps inserted order, is mutable, requires unique keys while values can repeat, and accesses values by key (e.g., d["a"]).
Empty Dictionary Syntax
{} creates an empty dictionary.
Empty Set Syntax
set() creates an empty set (since {} is reserved for an empty dictionary).
One-Item Tuple Syntax
A single-item tuple must include a trailing comma (e.g., (1,)); without the comma, Python treats it as just an integer.
List .append()
A list method that adds an item to the end of the list.
List .insert()
A list method that adds an element at the specified index position.
List .remove()
A list method that removes the first instance of the given value.
List .pop()
A list method that removes an item from a given index, defaulting to removing the last element if no index is passed.
List .index()
A list method that returns the first index position of the given value.
List .count()
A list method that returns how many times a given value appears in the list.
Slicing
Sequence slicing syntax [start:stop:stride], which is exclusive of the stop index.
String Immutability Rule
Strings cannot be modified in place; every string method returns a brand new string.
String .strip()
A string method that removes whitespace or newline characters from the beginning and end of a string.
String .split()
A string method that separates one string into multiple substrings at the given delimiter instance.
String .find()
A string method that returns the index position of the given substring, or returns −1 if it is not found.
Tuple Unpacking
Assigning elements of a tuple directly into variables (e.g., a, b = (1, 2) results in a = 1 and b = 2).
Tuple Methods
Tuples only possess two methods: count() and index().
Set .add()
Adds an item to a set; causes no change and produces no error if the value is already present in the set.
Set .remove()
Removes an item from a set, but raises a KeyError if the value is missing from the set.
Set .discard()
Removes an item from a set, with no change or error if the value is missing.
Set .pop()
Removes and returns an arbitrary item from the set, taking no arguments due to sets being unordered.
Set .clear()
Removes all elements, clearing the entire set.
Dictionary Key Access (d["key"])
Returns the value associated with the specified key, but raises a KeyError if the key is missing.
Dictionary .get()
Returns the value of the given key without raising an error if the key is missing.
del d["key"]
Deletes the specified key and its associated value pair from the dictionary.
Dictionary .keys()
A dictionary method that returns a view showing all the keys in the dictionary.
Dictionary .values()
A dictionary method that returns a view showing all the values in the dictionary.
Dictionary .items()
A dictionary method that returns a view showing all keys along with their corresponding value pairs.
File Mode "r"
Read mode (the default mode); opens a file and starts at the beginning, throwing a FileNotFoundError if the file does not exist.
File Mode "w"
Write mode; opens and erases all contents of the file, or creates a new empty file if it does not already exist.
File Processing Pattern
The standard sequence of file handling operations: open, use, close.
F.read()
A file method that reads the entire file content and returns it as a single string.
F.readline()
A file method that reads and returns the first or next single line of the file as a string.
F.readlines()
A file method that reads and returns all lines individually as a list, each ending in a newline.
F.close()
Saves file data to disk and releases the system file resource.
try Block
The exception handling block that always runs first, executing statements sequentially up to the first error.
except Block
The block that runs only if a matching error occurs in the try block; Python checks except blocks top to bottom and only runs the first match.
else Block (Exceptions)
The block in an exception construct that runs only if the try block finishes completely with no errors.
ValueError
An error raised when a function receives an argument that has the right data type but an inappropriate or invalid value (e.g., int("abc")).
TypeError
An error raised when an operation is applied to an object of the wrong type (e.g., "5" + 3, or attempting to index an unordered set or mutate an immutable string/tuple).
ZeroDivisionError
An error raised when attempting to divide or compute modulo (%) by 0.
IndexError
An error raised when attempting to access an index past the end of a list, string, or tuple (e.g., [1, 2, 3][5]).
KeyError
An error raised when attempting to access a non-existent dictionary key or removing a non-existent element with set.remove().
FileNotFoundError
An error raised when attempting to open a missing or non-existent file in "r" mode.
SyntaxError
An error raised when the code violates Python's formal grammar rules (e.g., a missing colon).
EOFError
An error raised when there is no more data to read from an input stream (end of input).
NameError
An error raised when a variable or function name is referenced without being previously defined.
Class
A blueprint for creating objects (e.g., class Dog:).
Instance (Object)
A concrete entity built from a class blueprint that receives its own copy of the class attributes (e.g., d = Dog("Rex")).
Attribute
A variable that belongs specifically to an instance of a class (e.g., self.name).
Method
A function defined inside a class whose first parameter must be self (e.g., def bark(self):).
Constructor (__init__)
A special method that automatically runs the moment an instance is created, used to set the initial values of attributes.
self
A parameter referring to the specific instance of the class that is calling the method, set fresh each time the method is invoked.
Operator Overloading
Defining custom behavior for standard Python operators (such as +, -, or ==) within a user-defined class.
__add__
The special method invoked when evaluating the a + b operator on class instances.
__sub__
The special method invoked when evaluating the a - b operator on class instances.
__mul__
The special method invoked when evaluating the a * b operator on class instances.
__eq__
The special method invoked when evaluating the equality operator a == b.
__lt__ and __gt__
Special methods invoked when evaluating comparison operators a < b and a > b, respectively.
__str__
The special method invoked by calling print(a) or str(a) to produce a readable string representation of an object.
__len__
The special method invoked by calling len(a) on an instance of a class.