Python Strings, Input, and Decisions
- 92Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
92 questions
- 1In Python, every object has a_____that indicates the kinds of operations allowed on it.
Hint
It tells Python what kind of object it is and what you can do with it.
Answer
type
Explanation
Every Python object has a type, which determines the kinds of operations that can be performed on it.
- 2Python uses_____to bind names to objects in memory.
Hint
These are names you can use later to refer to objects.
Answer
variables
Explanation
Variables bind names to objects in memory, making those objects accessible by name.
- 3Combinations of objects and operations that evaluate to values are called_____.
Hint
These combinations are evaluated by Python to produce values.
Answer
expressions
Explanation
Expressions combine objects and operations and evaluate to a value.
- 4In an assignment statement, Python evaluates the_____before assigning its result to the name on the left.
Hint
It is the side of the assignment that supplies the value.
Answer
right-hand side
Explanation
In an assignment statement, Python evaluates the right-hand side before binding its result to the name on the left.
- 5When an operation produces a different value from an immutable object, Python creates a_____.
Hint
The original value remains unchanged, while the operation produces this.
Answer
new object
Explanation
An operation such as adding one to a number creates a new object; it does not alter the original object.
- 6When a variable name is made to refer to a new object, the name is being_____.
Hint
The variable name is attached to a different object in memory.
Answer
rebinding
Explanation
Assigning a new value to an existing variable changes which object the name refers to; it does not modify the original object.
- 7In the assignment var = type of 5 times 4, the value bound to var is the object_____.
Hint
This example stores a description of the kind of object rather than a numeric value.
Answer
type
Explanation
The expression type of an integer value evaluates to the type object int, which can itself be assigned to a variable.
- 8When evaluating an expression with multiple operations, Python follows the_____to determine their order.
Hint
These rules establish which operation is performed first.
Answer
precedence rules
Explanation
Python follows precedence rules to determine the order in which operations in an expression are evaluated.
- 9A sequence of characters in Python is a_____.
Hint
This object type represents text as a sequence of characters.
Answer
string
Explanation
A string is a sequence of characters, which can include letters, digits, special characters, and newline or tab characters.
- 10Python strings are_____, so uppercase and lowercase versions of a letter are different.
Hint
Changing a letter's capitalization can change the character.
Answer
case sensitive
Explanation
Strings distinguish between uppercase and lowercase characters, so uppercase A and lowercase a are different.
- 11To create a string literal, enclose its characters in_____.
Hint
These marks enclose the characters of a string literal.
Answer
quotation marks
Explanation
Quotation marks tell Python that the enclosed characters should be treated as a string object.
- 12Joining two strings end to end with the plus operator is called_____.
Hint
This operation combines text sequences end to end.
Answer
concatenation
Explanation
The plus operator concatenates strings by joining their characters into a new string.
- 13When two strings are concatenated, Python creates a_____.
Hint
The joined sequence is created separately from its inputs.
Answer
new object
Explanation
Concatenating strings produces a new string object rather than changing either original string.
- 14To make concatenated strings appear separated, include a_____in the string data.
Hint
Add this character explicitly if you want words separated.
Answer
space
Explanation
String concatenation does not insert spaces automatically; a space must be included as a character in one of the strings.
- 15Multiplying a string by an integer makes Python_____the string's characters.
Hint
The operation produces multiple copies of the same sequence.
Answer
repeat
Explanation
Multiplying a string by an integer repeats its sequence of characters the specified number of times.
- 16String repetition uses a_____rather than two strings.
Hint
One operand is text; the other specifies how many copies to make.
Answer
string and a number
Explanation
The repetition operation works between a string and a number, in either order, when the number is an integer.
- 17To repeat a string successfully, its numeric multiplier must be an_____.
Hint
The repetition count must be a whole-number type.
Answer
integer
Explanation
A string sequence can be repeated only by an integer; multiplying it by a non-integer causes a type error.
- 18The len command returns the_____of a string, measured by its number of characters.
Hint
It counts how many characters the string contains.
Answer
length
Explanation
The len command returns the number of characters in a string.
- 19The string abc has a_____of three characters.
Hint
Count each character, including spaces if present.
Answer
length
Explanation
For a string containing a, b, and c, len returns 3 because there are three characters.
- 20Multiplying a string sequence by a non-integer raises a_____.
Hint
The problem is with the kinds of values used in the operation.
Answer
type error
Explanation
Trying to multiply a string sequence by a non-integer produces a type error because the operand types are incompatible.
- 21In Python, the first character of a string is at index_____.
Hint
Programming index counts begin one count before ordinary position numbers.
Answer
0
Explanation
Python uses zero-based indexing, so the first character is at index 0.
- 22With zero-based indexing, the second character of a string is at index_____.
Hint
The first character has index zero, so move up one for the next character.
Answer
1
Explanation
With zero-based indexing, the second character is at index 1.
- 23In the string abc, the character c is at index_____.
Hint
Start counting at zero: a, then b, then c.
Answer
2
Explanation
In the string abc, the character c is the third character and has index 2.
- 24To retrieve one character at a particular index, use_____.
Hint
This punctuation surrounds the position being accessed.
Answer
square brackets
Explanation
Square brackets with an index select an individual character from a string.
- 25Indexing a string at a valid position returns the_____at that position.
Hint
The result is one item from the sequence, not the whole string.
Answer
character
Explanation
A string index expression evaluates to the character at the specified position.
- 26Trying to access index 3 in the three-character string abc causes an_____.
Hint
The requested position does not exist in the sequence.
Answer
index error
Explanation
An index error occurs when a program tries to access a position outside the string's valid range.
- 27In Python, the index_____selects the last character of a string.
Hint
Negative indices count positions from the right end.
Answer
negative 1
Explanation
The index negative 1 refers to the last character of a string, making it a convenient way to access the rightmost character.
- 28Negative string indices count from the_____side of the string.
Hint
This is the end from which negative positions are counted.
Answer
right
Explanation
Python counts negative indices from the right-hand end of a string.
- 29For the three-character string abc, accessing index negative 4 causes an_____.
Hint
The requested position extends beyond the string's left end.
Answer
index error
Explanation
For a three-character string, negative 4 goes past its leftmost character and raises an index error.
- 30The final character can be selected with the index given by the_____.
Hint
If there are eleven characters, the final index is ten.
Answer
length of the string minus one
Explanation
The last valid nonnegative index is one less than the string's length.
- 31In a slice, the first value specifies the_____index.
Hint
It marks the first position included in the selected sequence.
Answer
start
Explanation
The first slice value specifies the index where the substring begins.
- 32In a slice, the second value specifies the_____index, which is excluded from the result.
Hint
The slice ends just before this index.
Answer
stop
Explanation
The stop index is the boundary of a slice and is not included in the result.
- 33In a slice, the third value specifies the_____, which controls how many positions to move between characters.
Hint
It controls how many positions are advanced between selections.
Answer
step
Explanation
The step determines how far to move between selected characters.
- 34If a slice omits its step, Python uses a default step of_____.
Hint
This default advances to the next adjacent character each time.
Answer
1
Explanation
When the step is omitted, Python uses a default step of 1, selecting each character in order.
- 35A slice with a positive step moves through the string from_____.
Hint
This follows the usual reading direction for English text.
Answer
left to right
Explanation
A positive step traverses the string from left to right.
- 36A slice with a negative step moves through the string from_____.
Hint
This direction is opposite to the usual reading direction.
Answer
right to left
Explanation
A negative step traverses the string from right to left.
- 37With a step of 1, a slice selects_____.
Hint
A step of one does not skip any positions.
Answer
every character
Explanation
A step of 1 selects each character between the start and stop positions.
- 38With a step of 2, a slice selects_____.
Hint
A two-position jump leaves one position between selected characters.
Answer
every other character
Explanation
A step of 2 advances two positions at a time, selecting every other character.
- 39For the string abcdefgh, slicing from index 3 up to but not including index 6 with the default step gives_____.
Hint
Begin at d and stop just before the character at index 6.
Answer
d, e, and f
Explanation
In abcdefgh, the slice from index 3 up to but not including index 6 selects indices 3, 4, and 5.
- 40For the string abcdefgh, using a slice with an omitted start and stop and a step of negative 1 gives_____.
Hint
A negative-one step reverses the traversal direction while including each character.
Answer
hgfedcba
Explanation
A slice with an omitted start and stop and a step of negative 1 traverses the entire string backward.
- 41A valid slice that selects no characters evaluates to the_____.
Hint
The result is a string containing no characters.
Answer
empty string
Explanation
When a slice's direction and bounds cannot include any characters, the result is an empty string.
- 42Python strings are_____, so their characters cannot be changed after creation.
Hint
This property means the object cannot be altered in place.
Answer
immutable
Explanation
Strings are immutable, meaning their characters cannot be changed after the string is created.
- 43Because strings are immutable, making a changed version requires Python to create a_____.
Hint
The modified version is separate from the original in memory.
Answer
new object
Explanation
To get a changed version of an immutable string, Python must create a new string object.
- 44The Python command that prompts for and receives a user's response is_____.
Hint
This command lets a running program receive information from the user.
Answer
input
Explanation
The input command displays a prompt and waits for the user to type a response and press Enter.
- 45Whatever a user types in response to input is returned as a_____.
Hint
Python initially treats the response as text, regardless of its appearance.
Answer
string
Explanation
The input command returns what the user typed as a string, even when the response looks like a number.
- 46The input command finishes collecting the response when the user presses_____.
Hint
The command waits for the user to press this key to finish entering a response.
Answer
Enter
Explanation
After the user presses Enter, the input command returns the typed characters as a string.
- 47To use a numeric input response as an integer, cast it with_____.
Hint
This cast converts text representing a whole number into a whole-number value.
Answer
int
Explanation
Wrapping input in int converts a numeric string response into an integer.
- 48If a user enters 3 and the response is not cast, printing five times the response produces_____.
Hint
Without converting the input, the operation repeats text.
Answer
33333
Explanation
If the input response is the string 3, multiplying it by 5 repeats the character five times rather than performing arithmetic.
- 49If a user enters 3, the response is cast to an integer, and the program multiplies it by 5, the result is_____.
Hint
After casting, multiply the integer value rather than repeating a character.
Answer
15
Explanation
Casting the input string 3 to an integer makes multiplication arithmetic, so five times three is 15.
- 50To make a program display an expression's result to the user, use_____.
Hint
This command sends chosen values to the screen.
Answer
print
Explanation
A print statement explicitly displays the result of an expression to the user when a program runs.
- 51Seeing an expression's value automatically in the interactive shell is described as_____.
Hint
This informal description contrasts shell evaluation with explicit output.
Answer
peeking into the value
Explanation
The shell displays a typed expression's value interactively, but this is not the same as printing output from a program file.
- 52By default, a print statement displays its result and then starts a_____.
Hint
A subsequent print result starts on the next line.
Answer
new line
Explanation
Each print statement ends by moving to a new line by default.
- 53A comma between objects in one print statement makes Python insert a_____between them.
Hint
This separator is inserted automatically between the values.
Answer
space
Explanation
When multiple objects are separated by commas within one print statement, Python places a space between the printed objects.
- 54Before concatenating an integer with strings, convert it to text using_____.
Hint
This conversion changes a value into text.
Answer
str
Explanation
The str cast converts a non-string value, such as an integer, into a string so it can be concatenated with other strings.
- 55The f-string format combines literal text with evaluated_____inside curly brackets.
Hint
This special string format can insert evaluated values into text.
Answer
string
Explanation
An f-string combines literal text with expressions, whose values Python evaluates before displaying the result.
- 56In an f-string, content outside curly brackets is printed as_____.
Hint
This portion is not evaluated as a Python expression.
Answer
literal text
Explanation
Text outside the curly brackets in an f-string is displayed exactly as written.
- 57In an f-string, Python evaluates the_____inside curly brackets before displaying the result.
Hint
These parts can contain variables or operations whose values are substituted.
Answer
expressions
Explanation
Python evaluates the expressions inside an f-string's curly brackets before printing the string.
- 58When inserting expression values into an f-string, you generally do not need manual_____.
Hint
This conversion step is not needed for inserted expression results.
Answer
casting
Explanation
F-strings can display expressions alongside literal text without manually converting their values to strings first.
- 59Newton's method finds polynomial roots numerically using_____.
Hint
The method improves an estimate step by step.
Answer
successive approximation
Explanation
Newton's method numerically searches for polynomial roots by repeatedly refining guesses through successive approximation.
- 60In the Newton next-guess calculation, the function and its derivative are evaluated at the_____.
Hint
The current estimate is the point at which both function values are evaluated.
Answer
original guess
Explanation
Newton's next-guess calculation uses the function and its derivative evaluated at the original guess.
- 61In Newton's next-guess calculation, the function value at the guess is divided by the function's_____at that guess.
Hint
This quantity describes how the function changes at the guess.
Answer
derivative
Explanation
The function value at the guess is divided by the derivative value at the same guess in the described Newton update.
- 62In the demonstrated Newton program, the derivative formula is supplied_____.
Hint
The programmer writes the derivative formula into the program rather than relying on automatic calculation.
Answer
manually
Explanation
The program does not automatically calculate the derivative; the derivative formula must be supplied explicitly in the code.
- 63An expression that checks whether a comparison is true or false produces a_____value.
Hint
This data type represents one of two truth values.
Answer
Boolean
Explanation
A comparison expression can evaluate to a Boolean value, either true or false, rather than to a number.
- 64Python uses the_____to test whether two values are equivalent.
Hint
This operator uses two equals marks and asks a question about values.
Answer
double equal sign
Explanation
In Python, a double equal sign checks whether two expressions are equivalent; it does not assign a value.
- 65In Python,_____is used for assignment.
Hint
This operator assigns rather than checks equivalence.
Answer
one equal sign
Explanation
A single equal sign performs assignment by binding the right-hand value to the name on the left.
- 66Python represents the not-equal comparison with an_____.
Hint
This comparison operator tests whether two values differ.
Answer
exclamation mark equal
Explanation
The exclamation mark followed by an equal sign is the not-equal comparison operator.
- 67The comparison of whether 2 is less than 3 evaluates to_____.
Hint
This is the Boolean result when the comparison is correct.
Answer
true
Explanation
A comparison evaluates to true when its stated relationship holds, such as two being less than three.
- 68Comparing lowercase a with uppercase A for equivalence evaluates to_____.
Hint
String comparisons distinguish capitalization.
Answer
false
Explanation
Uppercase A and lowercase a are different string characters, so they are not equivalent.
- 69The Boolean operator that reverses a truth value is_____.
Hint
This operator expresses the opposite of a Boolean expression.
Answer
not
Explanation
The not operator reverses a Boolean value, turning true into false and false into true.
- 70An and expression evaluates to true only when_____Boolean expressions are true.
Hint
An and condition requires every joined condition to hold.
Answer
both
Explanation
For an and expression to be true, both of its Boolean expressions must be true.
- 71The result of false and true is_____.
Hint
An and result fails as soon as one required condition is false.
Answer
false
Explanation
If either part of an and expression is false, the entire expression is false.
- 72The result of false or true is_____.
Hint
Only one of the joined conditions needs to hold.
Answer
true
Explanation
An or expression is true when at least one of its Boolean expressions is true.
- 73An or expression is false only when_____Boolean expressions are false.
Hint
If either side is true, the or result is true.
Answer
both
Explanation
An or expression is false only if both of its Boolean expressions are false.
- 74To combine Boolean expressions with the logical conjunction in Python, write the keyword_____.
Hint
Type this word between the two conditions.
Answer
and
Explanation
Python uses the written keyword and to combine Boolean expressions; a symbol used for bitwise operations is not equivalent.
- 75The Python keyword that begins a conditional decision block is_____.
Hint
This keyword begins a conditional block.
Answer
if
Explanation
An if statement introduces a decision point and checks whether its condition is true.
- 76An if block's commands execute when its condition is_____.
Hint
The block executes when the condition holds.
Answer
true
Explanation
The code inside an if block runs when its condition evaluates to true.
- 77Python determines which commands belong to a conditional block by their_____.
Hint
The visual offset at the start of a line defines the block's extent.
Answer
indentation
Explanation
Python uses indentation to determine which statements belong to a conditional block.
- 78An if statement's condition is followed by a_____before its indented block.
Hint
This punctuation appears at the end of the conditional header.
Answer
colon
Explanation
A colon follows the condition in an if statement and introduces the indented block.
- 79The keyword that introduces a branch for when an if condition is false is_____.
Hint
This branch covers the alternative case.
Answer
else
Explanation
An else block provides commands to run when the preceding if condition is false.
- 80In an if-else structure, Python executes_____the if branch or the else branch.
Hint
The program chooses one branch rather than running both.
Answer
either
Explanation
In an if-else structure, exactly one branch runs: the if branch or the else branch.
- 81To check another condition after an if branch fails, use_____.
Hint
It means an alternative conditional branch.
Answer
elif
Explanation
The elif keyword adds another condition to check when earlier conditions were false.
- 82In an if-elif chain, Python executes the_____condition that evaluates to true.
Hint
Once a matching branch is found, later alternatives are not selected.
Answer
first
Explanation
Python checks elif conditions in order and executes the first branch whose condition is true.
- 83An if-elif chain executes at most_____of its branches.
Hint
The branches are alternatives, not independent checks.
Answer
one
Explanation
An if-elif chain selects at most one of its branches, even if multiple conditions would be true.
- 84Without an else branch, if all conditions in a chain are false,_____of the branches execute.
Hint
Every condition must fail for this to happen.
Answer
none
Explanation
If every if and elif condition is false and there is no else branch, no branch in the chain executes.
- 85A final_____branch catches the case where no preceding condition is true.
Hint
It handles the remaining case after all tests fail.
Answer
else
Explanation
An else branch at the end of a chain acts as a catch-all when none of the preceding conditions is true.
- 86A command belongs to the rest of the program after a conditional when it is at the_____as the if statement.
Hint
Statements outside a block align with its header rather than being shifted inward.
Answer
same indentation level
Explanation
A statement aligned with the original if statement is outside its block and runs after the conditional, regardless of the condition's outcome.
- 87A conditional placed inside another conditional's block is called a_____conditional.
Hint
One decision block is placed inside another.
Answer
nested
Explanation
A conditional can appear inside the indented block of another conditional, creating a nested conditional.
- 88To make a print statement part of an if block, it must be_____.
Hint
Move the statement to the same block level as the other commands controlled by the if.
Answer
indented
Explanation
To make a print statement execute only when an if condition holds, place it inside the block by indenting it.
- 89When separate if statements must not all run for overlapping conditions, their conditions need to be_____.
Hint
The conditions must not be true at the same time if only one block should run.
Answer
mutually exclusive
Explanation
Separate if statements are independent, so multiple conditions may be true and multiple blocks may execute; to ensure only one executes, the conditions must be mutually exclusive or organized as an if-elif chain.
- 90Testing a program early and often helps programmers_____and find mistakes before they spread.
Hint
This process involves testing code and locating mistakes.
Answer
debug
Explanation
Running a program with different inputs helps detect and correct bugs early, before they affect later parts of the program.
- 91The combination of receiving user responses and displaying results is called_____.
Hint
These are the mechanisms for receiving data and showing results.
Answer
input/output
Explanation
Input and output let a program receive information from a user and display a response, making it interactive.
- 92Adding decision points that select among code paths is called_____.
Hint
This changes a program from strictly linear execution to conditional paths.
Answer
branching
Explanation
Branching introduces decision points so a program can choose which code to execute based on conditions.

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