1. Home
  2. Explore
  3. Computer Science
  4. Python Strings, Input, and Decisions

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Python Strings, Input, and Decisions

  • 92Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Python Objects
In Python, every object has a
that indicates the kinds of operations allowed on it.

92 questions

  1. 1
    In 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.

  2. 2
    Python 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.

  3. 3
    Combinations 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.

  4. 4
    In 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.

  5. 5
    When 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.

  6. 6
    When 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.

  7. 7
    In 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.

  8. 8
    When 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.

  9. 9
    A 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.

  10. 10
    Python 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.

  11. 11
    To 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.

  12. 12
    Joining 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.

  13. 13
    When 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.

  14. 14
    To 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.

  15. 15
    Multiplying 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.

  16. 16
    String 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.

  17. 17
    To 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.

  18. 18
    The 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.

  19. 19
    The 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.

  20. 20
    Multiplying 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.

  21. 21
    In 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.

  22. 22
    With 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.

  23. 23
    In 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.

  24. 24
    To 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.

  25. 25
    Indexing 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.

  26. 26
    Trying 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.

  27. 27
    In 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.

  28. 28
    Negative 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.

  29. 29
    For 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.

  30. 30
    The 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.

  31. 31
    In 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.

  32. 32
    In 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.

  33. 33
    In 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.

  34. 34
    If 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.

  35. 35
    A 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.

  36. 36
    A 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.

  37. 37
    With 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.

  38. 38
    With 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.

  39. 39
    For 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.

  40. 40
    For 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.

  41. 41
    A 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.

  42. 42
    Python 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.

  43. 43
    Because 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.

  44. 44
    The 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.

  45. 45
    Whatever 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.

  46. 46
    The 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.

  47. 47
    To 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.

  48. 48
    If 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.

  49. 49
    If 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.

  50. 50
    To 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.

  51. 51
    Seeing 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.

  52. 52
    By 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.

  53. 53
    A 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.

  54. 54
    Before 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.

  55. 55
    The 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.

  56. 56
    In 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.

  57. 57
    In 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.

  58. 58
    When 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.

  59. 59
    Newton'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.

  60. 60
    In 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.

  61. 61
    In 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.

  62. 62
    In 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.

  63. 63
    An 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.

  64. 64
    Python 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.

  65. 65
    In 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.

  66. 66
    Python 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.

  67. 67
    The 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.

  68. 68
    Comparing 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.

  69. 69
    The 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.

  70. 70
    An 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.

  71. 71
    The 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.

  72. 72
    The 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.

  73. 73
    An 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.

  74. 74
    To 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.

  75. 75
    The 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.

  76. 76
    An 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.

  77. 77
    Python 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.

  78. 78
    An 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.

  79. 79
    The 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.

  80. 80
    In 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.

  81. 81
    To 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.

  82. 82
    In 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.

  83. 83
    An 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.

  84. 84
    Without 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.

  85. 85
    A 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.

  86. 86
    A 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.

  87. 87
    A 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.

  88. 88
    To 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.

  89. 89
    When 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.

  90. 90
    Testing 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.

  91. 91
    The 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.

  92. 92
    Adding 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.

1 of 92
Question 1 of 92

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent