Essential Python Concepts
- 41Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
41 questions
- 1A Python object that cannot be changed after it is created is called_____.
Hint
Think of the opposite of an object that can be modified in place.
Answer
immutable
Explanation
Immutable objects cannot be changed after creation; assigning a new value to a variable does not modify the original object.
- 2A Python object whose contents can be modified after it is created is called_____.
Hint
Lists are an example of this kind of object.
Answer
mutable
Explanation
Mutable objects can be modified after creation, including through a reference held by another variable.
- 3Which built-in sequence type is immutable: list or tuple?_____
Hint
This type uses parentheses in its common literal form.
Answer
tuple
Explanation
A tuple is immutable, so its items cannot be reassigned after the tuple is created.
- 4Which built-in sequence type allows items to be changed in place: list or tuple?_____
Hint
This type is often used when a collection needs to grow or change.
Answer
list
Explanation
A list is mutable, so its items can be changed in place.
- 5Which built-in mapping type is mutable and stores key-value pairs?_____
Hint
It is commonly used to look up a value by a key.
Answer
dictionary
Explanation
A dictionary is mutable, so its contents can be added, removed, or changed.
- 6Which built-in collection type is mutable and stores unique elements?_____
Hint
This collection is useful when duplicate elements are not wanted.
Answer
set
Explanation
A set is mutable, so elements can be added or removed after it is created.
- 7Which group contains only immutable built-in types: strings, integers, floats, booleans, bytes, and tuples, or lists, sets, and dictionaries?_____
Hint
Choose the group whose members cannot be modified in place.
Answer
strings, integers, floats, booleans, bytes, and tuples
Explanation
Strings, integers, floats, booleans, bytes, and tuples are immutable types in Python.
- 8If two variables refer to the same list, changing an item through one variable also changes what is seen through the other because both refer to the same_____.
Hint
The variables act as two names pointing to one underlying thing.
Answer
object
Explanation
Assigning a mutable object such as a list to another variable creates an additional reference to that same object, not a separate list.
- 9If a variable holding an immutable value is reassigned, the other variable previously assigned that value is not changed, because the reassignment gives the first variable a new_____.
Hint
Reassignment changes what one variable is bound to, rather than modifying the old immutable object.
Answer
value
Explanation
With immutable objects, rebinding one variable does not alter the value associated with another variable.
- 10A function that sorts a passed-in list using its in-place sort operation can change the caller's list; this modification is a_____effect.
Hint
The phrase describes an unintended or additional change caused by a function.
Answer
side
Explanation
Sorting a list in place mutates the same object the caller passed, which is a side effect. Programmers should decide intentionally whether a function should mutate its inputs.
- 11A list comprehension is a compact way to create a list by placing a_____inside square brackets.
Hint
It iterates over values to generate the list's contents.
Answer
for loop
Explanation
A list comprehension uses a compact loop-like structure to produce a new list.
- 12In a list comprehension, the expression before the for clause specifies the_____to place in the resulting list.
Hint
It determines what each iteration contributes to the new list.
Answer
value
Explanation
The expression at the beginning of a list comprehension is evaluated for each iteration and its result is added to the list.
- 13The comprehension_____
[i for i in range(10)]produces integers from 0 through.Hint
The stop value in range is excluded.
Answer
9
Explanation
The range function starts at 0 by default and excludes its stop value, so range(10) produces 0 through 9.
- 14A list comprehension can include another comprehension as its element expression to create a_____list.
Hint
The resulting structure contains lists inside a list.
Answer
nested
Explanation
A nested list comprehension can build a list whose elements are themselves lists.
- 15In a list comprehension, an if clause includes a value only when its_____evaluates to true.
Hint
This part tests whether a generated value should be kept.
Answer
condition
Explanation
A conditional clause filters the values generated by a comprehension, retaining only those for which the condition is true.
- 16A comprehension that selects values for which_____
i % 2 == 0keeps onlynumbers.Hint
These integers are divisible by two with no remainder.
Answer
even
Explanation
A remainder of zero when dividing by two identifies an even number. With range(10), the retained values are 0, 2, 4, 6, and 8.
- 17In a function definition, the names listed in the function's parentheses are called_____.
Hint
These names act as placeholders for values the function can receive.
Answer
parameters
Explanation
Parameters are the names declared in a function definition to receive values.
- 18The values supplied when calling a function are called_____.
Hint
These are the actual values passed into the function.
Answer
arguments
Explanation
Arguments are the values provided to a function call; they are assigned to the function's parameters.
- 19When values are assigned to function parameters according to their position in the call, they are passed as_____arguments.
Hint
The first supplied value goes to the first parameter, and so on.
Answer
positional
Explanation
Positional arguments are matched to parameters based on their order in the function call.
- 20When a function call explicitly names a parameter, such as_____
y=2, the value is passed as aargument.Hint
This style identifies the destination parameter by name.
Answer
keyword
Explanation
A keyword argument specifies the parameter name along with its value, so it does not rely on position.
- 21In a function call, positional arguments must appear before_____arguments.
Hint
Python rejects a positional value placed after a named value in the same call.
Answer
keyword
Explanation
Positional arguments must come before keyword arguments; placing a positional argument after a keyword argument raises an error.
- 22A parameter declared with a default value, such as_____
z=10, iswhen calling the function.Hint
The caller may omit it and let the default be used.
Answer
optional
Explanation
A parameter with a default value is optional because the caller does not have to supply an argument for it.
- 23If an optional parameter is omitted, the function uses its_____value.
Hint
This value is specified in the function definition.
Answer
default
Explanation
A default value is used whenever the caller omits the corresponding optional parameter.
- 24A required positional parameter without a supplied value causes a function call to raise an error for a missing_____argument.
Hint
Unlike an optional parameter, this one has no default to fall back on.
Answer
required
Explanation
A required parameter must receive a value; otherwise, Python reports that a required argument is missing.
- 25A parameter written as_____
*argscollects extra positional arguments into a.Hint
This immutable sequence stores the additional positional values.
Answer
tuple
Explanation
The
*argsparameter gathers any extra positional arguments into a tuple, including an empty tuple when none are supplied. - 26A parameter written as_____
**kwargscollects extra keyword arguments into a.Hint
The names of the arguments become keys.
Answer
dictionary
Explanation
The
**kwargsparameter gathers extra keyword arguments into a dictionary, where each keyword is a key associated with its value. - 27Using one asterisk before a list in a function call unpacks its elements as separate_____arguments.
Hint
Each list element is assigned by its place in the call.
Answer
positional
Explanation
The
*unpacking operator expands an iterable such as a list into individual positional arguments. - 28Using two asterisks before a dictionary in a function call unpacks its entries as_____arguments.
Hint
Dictionary keys identify the names of the parameters receiving the values.
Answer
keyword
Explanation
The
**unpacking operator expands a dictionary into keyword arguments, using its keys as parameter names. - 29A function can accept both extra positional and extra keyword arguments by using_____
*argsand.Hint
This parameter gathers named arguments into a mapping.
Answer
**kwargs
Explanation
A function can use
*argsto collect extra positional arguments and**kwargsto collect extra keyword arguments. - 30The special name-and-value test used to check whether a Python file is being run directly is commonly called the_____guard.
Hint
Its name is associated with the main program entry point.
Answer
main
Explanation
The main guard checks whether the current module is being run as the main program rather than imported by another module.
- 31When a Python file is imported as a module, its top-level code normally executes during the_____process.
Hint
This is how one module makes another module's functions available.
Answer
import
Explanation
Importing a module causes Python to read and execute its top-level statements, which is why a main guard is useful.
- 32Putting startup code inside the main guard prevents that code from running merely because the file is_____.
Hint
The guard distinguishes direct execution from being brought in by another module.
Answer
imported
Explanation
Code inside the main guard runs when the file is executed directly, but not when it is imported as a module.
- 33A module can keep reusable utility functions available to other files while reserving program startup actions for_____execution.
Hint
This means running the module itself rather than loading it from another module.
Answer
direct
Explanation
The main guard allows a module to provide reusable functions while running startup behavior only when the module is executed directly.
- 34GIL stands for_____.
Hint
It is a lock associated with Python's interpreter.
Answer
Global Interpreter Lock
Explanation
The Global Interpreter Lock, or GIL, is the interpreter lock discussed in the context of Python threads.
- 35In the described GIL model, a thread must acquire the interpreter_____before executing Python code.
Hint
This mechanism grants a thread permission to proceed.
Answer
lock
Explanation
The GIL requires a thread to acquire the interpreter lock before executing Python code.
- 36Under the GIL behavior described, only_____thread can execute Python code at a time.
Hint
The lock limits simultaneous execution, even on a computer with multiple CPU cores.
Answer
one
Explanation
The GIL allows only one thread at a time to execute Python code, according to the behavior described in the content.
- 37A thread is a component of an application that is executed by the_____.
Hint
This hardware component carries out program instructions.
Answer
CPU
Explanation
A thread is an execution unit within an application that is carried out by the CPU.
- 38Dividing an application into separate threads so different parts can make progress is called_____.
Hint
The term combines multiple execution paths with threads.
Answer
multithreading
Explanation
Multithreading organizes different pieces of a program into separate threads so they can make progress as independent tasks.
- 39Because of the GIL behavior described, adding threads does not provide a CPU-bound Python program with a_____bonus.
Hint
The missing word refers to an improvement in speed or efficiency.
Answer
performance
Explanation
The content explains that the GIL prevents multiple threads from executing Python code simultaneously, so threading does not speed up the described CPU-bound work.
- 40Splitting a numeric workload into parts, computing each part, and combining the results is a way to try to_____work across threads.
Hint
This means carrying out separate portions of a task at the same time.
Answer
parallelize
Explanation
The example divides a sum into sections that could be processed simultaneously on separate cores in a language without the stated GIL limitation.
- 41Even when a Python program has multiple threads and multiple CPU cores, the GIL limits Python-code execution to one thread at a_____.
Hint
Complete the phrase describing simultaneity: “at a ___.”
Answer
time
Explanation
The GIL means that, in the behavior described, only one thread can execute Python code at a time, regardless of the number of CPU cores.

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