Object-Oriented Programming in Python
- 93Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
93 questions
- 1A programming style that organizes a program as a sequence of functions and step-by-step instructions is_____programming.
Hint
Think of code that proceeds from top to bottom through a sequence of steps.
Answer
procedural
Explanation
Procedural programming organizes code around procedures or functions that carry out an algorithm step by step.
- 2A programming paradigm that can pass functions around and use anonymous functions is_____programming.
Hint
This paradigm treats functions as values that can be used in different ways.
Answer
functional
Explanation
Functional programming includes features such as passing functions around and using anonymous functions.
- 3Python supports multiple programming paradigms, including procedural, functional, and_____programming.
Hint
This paradigm organizes programs around custom data types and their objects.
Answer
object-oriented
Explanation
Python is flexible and supports object-oriented programming alongside procedural and functional approaches.
- 4Object-oriented programming becomes especially useful as programs become longer, larger, and more_____.
Hint
Think about what happens to a program as its requirements and codebase grow.
Answer
complicated
Explanation
Classes and objects provide ways to organize increasingly complicated programs and their related data and functionality.
- 5The process of separating a task behind a function name so callers need not know its implementation details is called_____.
Hint
This concept hides how an operation works behind a simpler interface.
Answer
abstraction
Explanation
A function such as one that gets a name abstracts away the details of prompting the user and returning the result.
- 6Putting related data and functionality together inside a named class is called_____.
Hint
Think of bundling closely related code into one organized unit.
Answer
encapsulation
Explanation
Object-oriented programming uses classes to encapsulate related data and behavior together.
- 7A class can model an entity from the real world or a_____world, such as a Sorting Hat.
Hint
The Sorting Hat belongs to which kind of fictional setting?
Answer
fantasy
Explanation
Classes can represent real-world entities, such as students, or fantasy-world entities, such as a Sorting Hat.
- 8As a program grows, grouping related functions and data into named units helps improve code_____.
Hint
Consider how grouping related pieces of code makes a large program easier to navigate.
Answer
organization
Explanation
Object-oriented design groups related functionality and data, making complex code easier to organize.
- 9Returning a comma-separated pair of values in Python actually returns one_____containing both values.
Hint
This immutable sequence can hold multiple values as one object.
Answer
tuple
Explanation
A comma-separated return such as a name and a house returns one tuple containing both values, rather than two independent return values.
- 10A tuple is similar to a list as a collection, but it is_____after it is created.
Hint
Its contents cannot be reassigned after creation.
Answer
immutable
Explanation
Tuples are immutable, meaning their stored items cannot be changed after the tuple is created.
- 11A list is_____because its items can be changed after the list is created.
Hint
Unlike a tuple, this collection permits item assignment.
Answer
mutable
Explanation
Lists are mutable: code can update items at particular numeric indices.
- 12A dictionary stores data as pairs of_____and values.
Hint
These labels let you retrieve associated values by name.
Answer
keys
Explanation
A dictionary organizes information into key-value pairs, such as a name key and a house key.
- 13The main semantic advantage of a dictionary over a tuple is that descriptive keys make stored values more_____.
Hint
Keys explain what each value represents, rather than relying on its position.
Answer
explicit
Explanation
With a dictionary, code can access a value by a meaningful key such as name or house instead of remembering numeric positions.
- 14Lists and tuples are accessed by numeric_____, such as zero for the first item.
Hint
This is how a sequence's positions are referred to in code.
Answer
indices
Explanation
Sequences such as lists and tuples use numeric indices to access their items; Python uses zero-based indexing.
- 15A dictionary is accessed by its_____rather than by a numeric position.
Hint
For example, a student record can be accessed using the label for its house.
Answer
keys
Explanation
Dictionary lookup uses keys, commonly strings, to identify the associated values.
- 16Square brackets create a list literal, while parentheses are a visual cue for creating a_____.
Hint
This collection is immutable and can be written with parentheses around its values.
Answer
tuple
Explanation
Square brackets indicate a list when creating one, while parentheses are commonly used to indicate a tuple.
- 17Even though lists and tuples are created with different delimiters, both use square brackets when you_____into them.
Hint
This operation accesses an item by its position.
Answer
index
Explanation
Square brackets are used to access elements by numeric position in both lists and tuples.
- 18A list or tuple can contain another list or tuple, forming a_____collection.
Hint
One collection is placed inside another.
Answer
nested
Explanation
Python allows nested collections; an element of a list or tuple can itself be another collection.
- 19Dictionaries, like lists, are_____, so their contents can be changed after creation.
Hint
This property allows updating a key's associated value.
Answer
mutable
Explanation
A dictionary's values can be updated, just as items in a list can be changed.
- 20Tuples can be useful for defensive programming when the contained values should not_____.
Hint
Immutability can prevent accidental modifications by you or a colleague.
Answer
change
Explanation
Using a tuple for values that should remain fixed reduces the opportunity for bugs caused by unintended changes.
- 21A class is a blueprint or_____for creating objects with a chosen structure.
Hint
The lecture compared a class to a form that produces similarly structured things.
Answer
mold
Explanation
A class defines a template for objects, including the attributes and behavior they can have.
- 22In Python, classes allow programmers to invent their own_____types and give them names.
Hint
A class can define a custom kind of value, such as a student.
Answer
data
Explanation
A major feature of classes is the ability to define named custom data types.
- 23The keyword used to define a class in Python is_____.
Hint
It is the keyword that begins a class definition.
Answer
class
Explanation
A class definition begins with Python's class keyword, followed by the class name.
- 24By convention, a programmer-defined class name such as Student begins with a_____letter.
Hint
The convention distinguishes class names from ordinary lowercase variable names.
Answer
capital
Explanation
Python programmers commonly capitalize the first letter of their own class names.
- 25A specific value created from a class is an_____of that class.
Hint
It is the concrete result of using the class blueprint.
Answer
object
Explanation
An object is a particular creation from a class; it is also called an instance of the class.
- 26The process of creating a specific object from a class is called_____.
Hint
This term names the act of making an instance from a blueprint.
Answer
instantiation
Explanation
Instantiating a class creates an object, or instance, of that class.
- 27A value such as a student's name stored inside a particular object is an instance_____.
Hint
It is a variable that belongs to an individual object.
Answer
variable
Explanation
Instance variables store data associated with a specific object, such as that student's name or house.
- 28Dot notation is used to access an object's_____, such as its name or house.
Hint
These are the properties or data stored inside an object.
Answer
attributes
Explanation
An object's attributes are accessed using dot notation, for example, a student object's name attribute.
- 29The dot in an expression such as student.name provides access to a member inside another_____.
Hint
The expression accesses something belonging to the value before the dot.
Answer
object
Explanation
Dot notation accesses an attribute or method that belongs to an object or, in some cases, a module.
- 30A class definition is code that acts as a template, while an object is a particular_____of that class.
Hint
This is another term for a specific object created from a class.
Answer
instance
Explanation
The class defines a data type; each object is an instance, or specific realization, of that class.
- 31Python's interpreter manages where objects are stored in computer_____.
Hint
The programmer generally does not need to manage the object's low-level storage location.
Answer
memory
Explanation
Python handles the lower-level details of allocating memory for objects, allowing programmers to work at a higher level.
- 32A class's initialization method is conventionally named Dunder_____.
Hint
Its name refers to initializing a newly created object's contents.
Answer
init
Explanation
The special init method is called automatically to initialize an object's attributes when an object is created.
- 33When an instance method is called, Python automatically supplies a reference to the current object through the first parameter, conventionally named_____.
Hint
This conventional parameter gives a method access to the current instance.
Answer
self
Explanation
Instance methods receive the current object as their first argument, conventionally called self.
- 34Inside an initializer, assigning self.name = name stores the passed-in value as an object_____.
Hint
It becomes a named piece of data associated with that object.
Answer
attribute
Explanation
The assignment creates or sets the object's name attribute, commonly described as an instance variable.
- 35Calling a class name with parentheses, such as Student(name, house), is a_____call that creates an object.
Hint
This call uses the class as a template to create a new instance.
Answer
constructor
Explanation
A constructor call instantiates an object and supplies values used to initialize it.
- 36Python's init method initializes an object, while the special new method handles its initial_____in memory.
Hint
The lecture distinguished initialization from the lower-level act of making an empty object.
Answer
creation
Explanation
Python technically separates object creation, handled by new, from initialization of its contents, handled by init.
- 37Using default parameter values in a method signature makes those parameters_____for callers.
Hint
A caller can omit an argument that already has a default value.
Answer
optional
Explanation
A parameter with a default value does not have to be supplied by the caller.
- 38A method placed inside a class is still a function, but it is called a_____.
Hint
This is the name for a function defined as part of a class.
Answer
method
Explanation
Functions defined inside classes are called methods; they can define behavior for the class's objects.
- 39An initializer can validate input before storing it, for example by rejecting an empty name with a_____error.
Hint
This exception is appropriate when a supplied value is invalid.
Answer
ValueError
Explanation
The example raises a ValueError when a name is missing, rather than creating a student with invalid data.
- 40The Python keyword used by a programmer to signal an exception is_____.
Hint
It is the counterpart to catching an exception with try and except.
Answer
raise
Explanation
Programmers can raise exceptions such as ValueError when their own validation detects invalid input.
- 41Passing an explanatory message when raising an exception helps identify what went_____.
Hint
The message tells the programmer why the exception occurred.
Answer
wrong
Explanation
An exception message such as missing name or invalid house makes the cause clearer to the programmer.
- 42Using an exception to report invalid input is generally preferable to abruptly ending the entire program with_____.
Hint
This approach stops the whole program rather than signaling a recoverable problem.
Answer
sys.exit
Explanation
Raising an exception lets calling code handle the problem with try and except; exiting the entire program can be an unnecessarily extreme response.
- 43The term for a function inside a class that is called with an object and operates on that instance is an_____method.
Hint
It receives the particular object through self.
Answer
instance
Explanation
An instance method operates on a particular object and receives that object as self.
- 44Python automatically calls a class's Dunder str method when an object needs to be represented as a_____.
Hint
The method customizes what print displays for the object.
Answer
string
Explanation
Defining the str method lets a class provide a readable string representation instead of the default representation showing an object location.
- 45Without a custom string method, printing an object typically displays a default representation that can include its class and a memory_____.
Hint
The default output is usually not as informative or user-friendly as a custom description.
Answer
location
Explanation
The default object representation can show the object's type and a location-like value, which is generally less useful to a user.
- 46A method that performs an action designed by the programmer, such as charm, is a_____method.
Hint
Unlike special methods, the programmer chooses this method's name and behavior.
Answer
custom
Explanation
Classes can define their own methods to represent actions or functionality specific to their objects.
- 47A getter is a method used to_____an attribute's value.
Hint
Its purpose is to provide access to a value.
Answer
get
Explanation
A getter retrieves an attribute, potentially allowing the class to control how that value is accessed.
- 48A setter is a method used to_____an attribute's value.
Hint
Its purpose is to assign a value, potentially after validation.
Answer
set
Explanation
A setter handles attempts to assign an attribute and can validate the new value before storing it.
- 49In Python, the decorator used to define a property getter is_____.
Hint
It marks a method so the attribute can be accessed like a property.
Answer
property
Explanation
The property decorator turns a getter method into a property that can be accessed with dot notation.
- 50A property setter is associated with its property using a decorator based on the property name followed by_____.
Hint
The decorator indicates that the method assigns the property's value.
Answer
setter
Explanation
For a property named house, the setter is defined with the corresponding house setter decorator.
- 51A getter for an instance property takes only the automatically supplied_____argument.
Hint
It needs access to the current object, but no new value is being supplied.
Answer
self
Explanation
A getter needs the current instance to retrieve its property, so it takes self and no separate value argument.
- 52A setter takes the current object and the new_____to assign.
Hint
Unlike a getter, a setter needs the proposed replacement value.
Answer
value
Explanation
A setter typically takes self plus one additional argument containing the value the caller wants to set.
- 53When code assigns to a property using dot notation and an equals sign, Python can automatically call its_____.
Hint
This method checks assignments before the underlying value is changed.
Answer
setter
Explanation
A property's setter intercepts assignments so the class can validate or otherwise control the new value.
- 54A property getter and setter can keep validation in one place and help protect an object's_____.
Hint
The methods prevent invalid values from being assigned freely.
Answer
data
Explanation
Properties allow a class to validate values both during initialization and later assignments, helping preserve data correctness.
- 55A leading underscore on an instance variable is a Python convention asking other programmers not to_____it directly.
Hint
It signals that the variable is intended for internal use, but does not technically block access.
Answer
touch
Explanation
Python does not enforce private visibility in the same way some languages do; a leading underscore is an honor-system convention that the attribute should not be accessed directly.
- 56Two leading underscores can signal an even stronger convention that an attribute should not be_____.
Hint
This convention still does not make the attribute absolutely inaccessible.
Answer
touched
Explanation
A double underscore is a stronger signal to avoid direct access, but Python does not make circumvention impossible.
- 57Python's approach to access control relies heavily on conventions rather than strict language-enforced_____.
Hint
This refers to whether members are public, protected, or private.
Answer
visibility
Explanation
Unlike some languages, Python does not strictly prevent programmers from accessing attributes marked by naming conventions; it relies on programmers respecting those conventions.
- 58A class variable belongs to the class itself, whereas an instance variable belongs to a specific_____.
Hint
An instance variable can differ from one created instance to another.
Answer
object
Explanation
Class variables are shared at the class level; instance variables store data for particular objects.
- 59A class variable has one shared copy used by the class's_____.
Hint
These are the instances created from the class.
Answer
objects
Explanation
Objects of a class can share a class variable, while each object can also have its own instance variables.
- 60The decorator used to designate a method as a class method is_____.
Hint
It marks a method that operates in relation to the class rather than a particular instance.
Answer
classmethod
Explanation
The classmethod decorator defines a method that receives a reference to its class instead of an instance reference.
- 61The conventional first parameter of a class method is_____.
Hint
This short name refers to the class itself, rather than an individual object.
Answer
cls
Explanation
A class method receives the class as its first argument, conventionally named cls.
- 62A class method can be called using the_____name without first creating an instance.
Hint
The class itself provides access to this method.
Answer
class
Explanation
Class methods are callable through the class, which is useful when the operation does not require a particular object.
- 63A class method is appropriate when functionality relates to the class as a whole rather than a particular_____.
Hint
The operation does not depend on one object's individual state.
Answer
instance
Explanation
Class methods receive the class itself and are useful for behavior shared at the class level.
- 64A static method is another method type in Python and is designated with the_____decorator.
Hint
It is distinct from both instance methods and class methods.
Answer
staticmethod
Explanation
Python supports static methods through a decorator, though the lecture did not explore them in depth.
- 65Moving a get student function into the Student class can keep student-related functionality_____together.
Hint
The design places related behavior in the same named unit as the data it concerns.
Answer
encapsulated
Explanation
Grouping student-specific operations inside the Student class makes the class a central place to find related behavior.
- 66A class method can solve the circular design problem of needing an object before calling a method that is supposed to create that_____.
Hint
The method can be called from the class itself, before an instance exists.
Answer
object
Explanation
A class method such as get can construct and return a new instance without requiring an existing instance first.
- 67When one class inherits attributes or methods from another, the process is called_____.
Hint
It establishes a parent-child relationship between classes.
Answer
inheritance
Explanation
Inheritance lets a subclass reuse functionality defined by its superclass.
- 68The class that inherits from another class is called the_____class.
Hint
It is the child in the class hierarchy.
Answer
subclass
Explanation
A subclass inherits from a parent class, also called a superclass.
- 69The class from which another class inherits is called its_____class.
Hint
It is the parent in the class hierarchy.
Answer
superclass
Explanation
A superclass provides methods or attributes that a subclass can inherit.
- 70Inheritance can factor shared data and behavior, such as a name common to students and professors, into a_____class.
Hint
The shared parent class stores functionality used by its subclasses.
Answer
superclass
Explanation
A common Wizard superclass can define name storage and validation once for both Student and Professor subclasses.
- 71In a class definition, naming a parent class in parentheses specifies the new class's_____relationship.
Hint
The syntax tells Python which class to derive from.
Answer
inheritance
Explanation
A class definition that lists a parent class establishes that the new class inherits from it.
- 72The built-in function_____provides access to a class's parent when implementing inherited behavior.
Hint
It is commonly used to call the parent class's initializer.
Answer
super
Explanation
Calling super and then the parent method allows a subclass to reuse the superclass's behavior.
- 73A subclass can call its superclass's initializer to reuse shared setup, such as assigning and validating a_____.
Hint
This is an attribute shared by both student and professor examples.
Answer
name
Explanation
Calling the superclass initializer lets it perform shared initialization, while the subclass adds its own attributes such as house or subject.
- 74A subclass can add specialized attributes of its own after reusing its superclass's shared_____.
Hint
For example, a student adds a house while a professor adds a subject.
Answer
functionality
Explanation
Inheritance allows subclasses to reuse common setup and then add behavior or data specific to their role.
- 75Classes can inherit through multiple levels, so a class may gain functionality from its parent and more distant_____.
Hint
These are classes higher in the inheritance hierarchy.
Answer
ancestors
Explanation
Inherited behavior can pass through several levels of a class hierarchy.
- 76A subclass may_____inherited behavior to make it work differently for that subclass.
Hint
This means providing a new implementation in the child class.
Answer
override
Explanation
A subclass can replace or customize inherited behavior by overriding a method.
- 77Python exceptions form a class_____in which specific exceptions inherit from broader exception classes.
Hint
For example, ValueError has a more general parent exception type.
Answer
hierarchy
Explanation
Built-in exceptions are arranged in a hierarchy so related errors can share behavior and be caught at different levels.
- 78ValueError inherits from_____in Python's exception hierarchy.
Hint
This is its more general parent class.
Answer
Exception
Explanation
ValueError is a specific exception class that descends from the broader Exception class.
- 79Catching a parent exception class can handle multiple more specific exception_____.
Hint
This can avoid listing every related child exception separately.
Answer
types
Explanation
Because exceptions inherit from parent classes, a handler can catch a broader superclass when several specific errors should be handled alike.
- 80The technique of defining how operators behave for custom objects is called operator_____.
Hint
A familiar symbol can be given a class-specific meaning.
Answer
overloading
Explanation
Operator overloading lets a class implement how common operators, such as plus, work with its objects.
- 81Python's plus operator can mean arithmetic addition or string_____depending on the operand types.
Hint
For strings, plus joins text together rather than adding numbers.
Answer
concatenation
Explanation
Python overloads plus for different types; it can add numbers or concatenate strings.
- 82The special method used to define what plus means for instances of a class is Dunder_____.
Hint
Its name is the English verb for combining values with the plus operator.
Answer
add
Explanation
Defining the add special method allows a class to specify how its objects behave with plus.
- 83In an overloaded addition method, self represents the operand on the_____of the plus sign.
Hint
It is the object whose class's addition method is invoked.
Answer
left
Explanation
For an expression such as Potter plus Weasley, self represents the left operand and the other parameter represents the right operand.
- 84In an overloaded addition method, the second parameter represents the operand on the_____of the plus sign.
Hint
It is conventionally named other.
Answer
right
Explanation
The addition method receives the right-hand operand as its second argument, conventionally called other.
- 85To add two vault objects, the overloaded addition method can sum matching coin attributes and return a_____vault.
Hint
The combined result is a separate object containing the totals.
Answer
new
Explanation
The example adds the gallions, sickles, and canuts from both operands, then returns a newly constructed Vault holding those totals.
- 86Python does not generally let programmers invent arbitrary new operator_____from any characters they choose.
Hint
Only supported operator forms can be overloaded.
Answer
symbols
Explanation
Python provides a defined set of operators that classes can overload; programmers cannot freely create arbitrary operators.
- 87The built-in_____function can reveal the class of a value, which is useful for inspecting types while experimenting.
Hint
Calling it on a value such as 50 reports its type.
Answer
type
Explanation
The type function returns information about a value's class, though such output is often more useful for exploration than for user-facing output.
- 88In Python, int is itself a_____used to create integer objects.
Hint
Calling it with a suitable value creates an instance of the integer type.
Answer
class
Explanation
The int class constructs integer objects, including when converting a string to an integer.
- 89Python's str type is a class, and calling its methods such as lower or strip operates on string_____.
Hint
These are individual values created from the str class.
Answer
objects
Explanation
Strings are objects of the str class, whose methods include lower for changing case and strip for removing surrounding whitespace.
- 90The list class provides methods such as append, which adds an item to the current_____.
Hint
The method changes this mutable sequence by adding an element.
Answer
list
Explanation
Calling append uses a method provided by the list class to add an item to that list object.
- 91The built-in dict type is a_____whose objects provide methods for working with key-value pairs.
Hint
It is the type used to create dictionary objects.
Answer
class
Explanation
Dictionaries are instances of the dict class, which supplies their behavior and methods.
- 92The built-in classes int, str, list, and dict show that Python's familiar data types are implemented using_____and objects.
Hint
These are the templates from which the built-in values are created.
Answer
classes
Explanation
Python's standard types are classes, and values of those types are objects with associated methods and behavior.
- 93A programmer-defined class can combine instance variables, methods, properties, and custom operator_____.
Hint
These features allow the class to define how its objects store data and act.
Answer
behavior
Explanation
Classes let programmers create custom data types with their own data, methods, property controls, and operator behavior.

Ask anything
We've read this whole study set, so questions about it get the best answers.