1. Home
  2. Explore
  3. Computer Science
  4. Python Programming Basics

Study methods

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

Python Programming Basics

  • 138Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Python Setup
Python is especially useful for writing scripts, automating tasks, and pursuing programming
.

138 questions

  1. 1
    Python is especially useful for writing scripts, automating tasks, and pursuing programming
    _____
    .
    Hint

    Think of the career opportunities mentioned alongside automation.

    Answer

    jobs

    Explanation

    The content describes Python as a popular language that is highly sought after for jobs, as well as useful for automation and scripts.

  2. 2
    Compared with many programming languages, Python is described as having relatively little
    _____
    to learn.
    Hint

    This refers to the rules for writing code in a language.

    Answer

    syntax

    Explanation

    The course introduction emphasizes that Python has less syntax to learn than many languages, which can make it more beginner friendly.

  3. 3
    Of the two major Python versions discussed, Python
    _____
    is the older legacy version.
    Hint

    It is contrasted with the version described as the future of Python.

    Answer

    Python 2

    Explanation

    Python 2 is described as a legacy version that is no longer officially maintained or supported.

  4. 4
    The version described as actively maintained and supported going forward is
    _____
    .
    Hint

    It is the newer version selected for the course.

    Answer

    Python 3

    Explanation

    Python 3 is presented as the future of Python and the version receiving ongoing maintenance and support.

  5. 5
    The course chooses
    _____
    as the version beginners should use for its examples.
    Hint

    The course selects the newer, actively supported version.

    Answer

    Python 3

    Explanation

    The tutorials use Python 3, while noting that learning it also helps a programmer transition to Python 2.

  6. 6
    Python 2 was said to have more existing libraries and
    _____
    written for it.
    Hint

    This refers to the amount of software already created in that version.

    Answer

    Python code

    Explanation

    The content notes that Python 2 had been around longer, so more libraries and Python code had been written for it.

  7. 7
    Learning Python 3 still makes it possible to move into coding in
    _____
    .
    Hint

    The course says the differences between the two versions are not very large.

    Answer

    Python 2

    Explanation

    The content explains that the version differences are relatively small, so a learner of Python 3 can also code in Python 2.

  8. 8
    An IDE is an integrated development
    _____
    used to write, run, and debug code.
    Hint

    The final word in the expansion of IDE names a workspace for development.

    Answer

    environment

    Explanation

    IDE stands for integrated development environment, a specialized program for working with code.

  9. 9
    The IDE selected for the course is
    _____
    .
    Hint

    It is a popular Python IDE from JetBrains.

    Answer

    PyCharm

    Explanation

    The tutorials use PyCharm as their integrated development environment.

  10. 10
    PyCharm's Community version is described as free and
    _____
    source.
    Hint

    This describes software whose source code is available for use and modification.

    Answer

    open

    Explanation

    The course selects the Community version because it is free and open source; the Professional version is paid.

  11. 11
    When creating a PyCharm project for this course, the selected interpreter should be
    _____
    .
    Hint

    The interpreter determines which Python version runs the project.

    Answer

    Python 3

    Explanation

    Selecting Python 3 as the project interpreter is necessary to follow the course's examples correctly.

  12. 12
    The command-line tool described as a package manager for installing Python modules is
    _____
    .
    Hint

    It is commonly used with an install command to add packages.

    Answer

    pip

    Explanation

    pip can install, manage, update, and uninstall Python modules, including third-party packages.

  13. 13
    In Python, a program is fundamentally a set of
    _____
    for the computer.
    Hint

    These tell the computer what actions to perform.

    Answer

    instructions

    Explanation

    Programming is described as specifying instructions that a computer executes to carry out tasks.

  14. 14
    A Python program executes its written lines of code in
    _____
    .
    Hint

    Changing the placement of a line can change when it runs.

    Answer

    order

    Explanation

    Python executes program instructions sequentially, so the order in which lines are written matters.

  15. 15
    The Python function used in the examples to display text or other output is
    _____
    .
    Hint

    It sends output to the screen or console.

    Answer

    print

    Explanation

    A print statement displays its contents, such as a message or a drawn text shape, in the console.

  16. 16
    The window where Python outputs information from print statements is the
    _____
    .
    Hint

    It is the output area shown below the editor in the examples.

    Answer

    console

    Explanation

    The console displays information produced by a running program, including text printed by print.

  17. 17
    In PyCharm, a new source file for a Python program is created as a
    _____
    file.
    Hint

    It uses the language's source-file type.

    Answer

    Python

    Explanation

    The course creates a new Python file in the project before writing its first program.

  18. 18
    The sample program that prints a conventional introductory greeting is called
    _____
    .
    Hint

    It is a traditional first program in many programming courses.

    Answer

    hello world

    Explanation

    The hello world program demonstrates a basic use of print to display a message.

  19. 19
    In Python, creating a text-based triangle with multiple print statements demonstrates that output can be
    _____
    from text.
    Hint

    The programmer describes the shape using the characters and spacing to display.

    Answer

    specified

    Explanation

    The example draws a shape by specifying its rows as strings inside print statements.

  20. 20
    A Python instruction inside a function or control structure is marked by
    _____
    .
    Hint

    Python uses leading whitespace to show code blocks.

    Answer

    indentation

    Explanation

    Indented lines belong to the block introduced by a function, loop, or conditional statement.

  21. 21
    A line beginning with the hash symbol is treated by Python as a
    _____
    .
    Hint

    It is written for people reading the code and is not executed.

    Answer

    comment

    Explanation

    Python ignores a comment beginning with the hash symbol during program execution.

  22. 22
    Temporarily making Python ignore a line without deleting it is called
    _____
    out the code.
    Hint

    This uses a comment marker to disable code during testing.

    Answer

    commenting

    Explanation

    Commenting out code preserves it in the file while preventing Python from executing it.

  23. 23
    A variable is a container used to store a data
    _____
    .
    Hint

    It is information that the program may later retrieve or change.

    Answer

    value

    Explanation

    Variables provide named containers for storing data used in a program.

  24. 24
    Using variables for a character's name and age avoids changing each repeated value
    _____
    throughout a long story.
    Hint

    A variable lets repeated references update from one stored value.

    Answer

    manually

    Explanation

    Storing a name or age once in a variable makes it easier to update every use throughout a program.

  25. 25
    In Python variable names, the course recommends separating words with an
    _____
    .
    Hint

    It is the character used in names such as character name.

    Answer

    underscore

    Explanation

    The examples use an underscore between words in variable names, such as character name and character age.

  26. 26
    The assignment operator used to give a variable a value is
    _____
    .
    Hint

    It is the symbol used between a variable name and its value.

    Answer

    equals

    Explanation

    An equals sign assigns the value on its right to the variable on its left.

  27. 27
    A variable's value can be changed later by assigning it a
    _____
    value.
    Hint

    For example, a character's name could change partway through a story.

    Answer

    new

    Explanation

    Reassigning a variable updates the value it stores, so later references use the new value.

  28. 28
    The Python data type used to store plain text is a
    _____
    .
    Hint

    Names and story text are common examples.

    Answer

    string

    Explanation

    A string represents plain text and is written inside quotation marks in the examples.

  29. 29
    Whole numbers and decimal numbers are both examples of the basic data type
    _____
    .
    Hint

    This data type supports values such as an age or a decimal measurement.

    Answer

    numbers

    Explanation

    The content identifies numbers, including whole and decimal numbers, as one of Python's basic data types.

  30. 30
    A value that can be either true or false is a
    _____
    value.
    Hint

    It is commonly used to represent yes-or-no conditions.

    Answer

    Boolean

    Explanation

    Boolean values represent true or false information and are frequently used in programming.

  31. 31
    The three basic data categories emphasized for new Python programmers are strings, numbers, and
    _____
    values.
    Hint

    This category represents true-or-false data.

    Answer

    Boolean

    Explanation

    The course highlights strings, numbers, and Boolean values as the basic types beginners will often use.

  32. 32
    A string is created by enclosing text in
    _____
    marks.
    Hint

    Python uses these marks to identify the beginning and end of a text literal.

    Answer

    quotation

    Explanation

    Quotation marks designate text as a string in Python.

  33. 33
    The escape sequence described as inserting a new line in a string is backslash followed by the letter
    _____
    .
    Hint

    The character stands for a new line.

    Answer

    n

    Explanation

    The backslash n escape sequence inserts a line break into a string.

  34. 34
    To include a quotation mark inside a string without ending the string, use the backslash as an
    _____
    character.
    Hint

    It tells Python to render the following character literally.

    Answer

    escape

    Explanation

    The backslash is an escape character; for example, it can make a quotation mark part of the string.

  35. 35
    Combining a string with another string by appending it is called
    _____
    .
    Hint

    The operation joins text values together.

    Answer

    concatenation

    Explanation

    Concatenation appends one string to another, such as adding a phrase to a stored string.

  36. 36
    In the examples, the string method that converts text to lowercase is
    _____
    .
    Hint

    It changes all letters to the smaller letter case.

    Answer

    lower

    Explanation

    The lower method returns a lowercase form of the string.

  37. 37
    The string method that converts all letters to uppercase is
    _____
    .
    Hint

    It changes all letters to capital letters.

    Answer

    upper

    Explanation

    The upper method returns an uppercase form of the string.

  38. 38
    The string method that checks whether all letters are uppercase returns a
    _____
    or false value.
    Hint

    It reports a yes-or-no result about the string's letter case.

    Answer

    true

    Explanation

    The is upper method returns true when the string is entirely uppercase and false otherwise.

  39. 39
    The built-in function used to find how many characters are in a string is
    _____
    .
    Hint

    The name abbreviates the idea of length.

    Answer

    len

    Explanation

    The len function returns the number of characters in a string.

  40. 40
    Python string indexing starts with position
    _____
    for the first character.
    Hint

    The first position is not numbered one in Python.

    Answer

    zero

    Explanation

    Python uses zero-based indexing, so the first character is at index zero.

  41. 41
    The string method that finds the position where a specified character or substring starts is
    _____
    .
    Hint

    It returns the location of a search value in the string.

    Answer

    index

    Explanation

    The index method reports the position of a specified value; it raises an error if that value is not found.

  42. 42
    The string method that substitutes one specified piece of text for another is
    _____
    .
    Hint

    It takes the old text and the new text as inputs.

    Answer

    replace

    Explanation

    The replace method returns a string in which the specified text has been changed to replacement text.

  43. 43
    The arithmetic operator that returns the remainder after division is the
    _____
    operator.
    Hint

    For example, ten divided by three leaves a remainder of one.

    Answer

    modulus

    Explanation

    The modulus operator returns the remainder from dividing the first number by the second.

  44. 44
    The function that converts a value to a whole-number type is
    _____
    .
    Hint

    It cannot preserve a decimal part when converting to an integer.

    Answer

    int

    Explanation

    The int function converts a suitable value to an integer, a whole number without a decimal part.

  45. 45
    The function used to convert a value to a decimal number type is
    _____
    .
    Hint

    It allows a number to have a fractional part.

    Answer

    float

    Explanation

    The float function converts a suitable value to a decimal number type.

  46. 46
    When a number must be joined with text for output, it can first be converted to a string with
    _____
    .
    Hint

    This function changes a value's type to text.

    Answer

    str

    Explanation

    The str function converts a number to a string so it can be combined with text for output.

  47. 47
    The function that returns a number's distance from zero, ignoring its sign, is
    _____
    .
    Hint

    It gives the absolute value of a number such as negative five.

    Answer

    abs

    Explanation

    The abs function returns the absolute value, so the absolute value of negative five is five.

  48. 48
    The function that raises a base number to a specified power is
    _____
    .
    Hint

    It accepts a number and an exponent.

    Answer

    pow

    Explanation

    The pow function can calculate a value such as three raised to the second power.

  49. 49
    The function that returns the larger of the values passed to it is
    _____
    .
    Hint

    It selects the greatest value among its inputs.

    Answer

    max

    Explanation

    The max function returns the largest value passed to it.

  50. 50
    The function that returns the smallest of the values passed to it is
    _____
    .
    Hint

    It selects the least value among its inputs.

    Answer

    min

    Explanation

    The min function returns the smallest value passed to it.

  51. 51
    The function that rounds a number according to standard rounding rules is
    _____
    .
    Hint

    A decimal part such as point seven rounds upward in the example.

    Answer

    round

    Explanation

    The round function rounds a number to a nearby whole number using standard rounding rules.

  52. 52
    The math function that discards the decimal part by rounding downward is
    _____
    .
    Hint

    It returns the lower whole-number value.

    Answer

    floor

    Explanation

    The floor function rounds down to the lowest whole-number value, effectively removing the fractional portion in the examples.

  53. 53
    The math function that rounds a number upward is
    _____
    .
    Hint

    It moves a non-whole value up to the next whole number.

    Answer

    ceil

    Explanation

    The ceil function rounds a number up to the next whole-number value.

  54. 54
    The math function used to calculate the square root of a number is
    _____
    .
    Hint

    For example, it returns six when given thirty-six.

    Answer

    sqrt

    Explanation

    The sqrt function returns the square root of its input.

  55. 55
    Python code uses an
    _____
    to request information from a user.
    Hint

    This function can display a prompt and wait for a response.

    Answer

    input

    Explanation

    The input function lets a user type information into a running program.

  56. 56
    By default, the value returned by input is a
    _____
    .
    Hint

    This remains true even if the user types digits.

    Answer

    string

    Explanation

    Python treats user input as text by default, so it must be converted when a number is needed.

  57. 57
    A list is a data structure used to store multiple
    _____
    in an organized way.
    Hint

    These can be related items such as friends' names or lucky numbers.

    Answer

    values

    Explanation

    Lists group multiple values together so a program can organize and manage them.

  58. 58
    Python list literals are enclosed in square
    _____
    .
    Hint

    They appear on both sides of the list's elements.

    Answer

    brackets

    Explanation

    Square brackets identify a list literal in Python.

  59. 59
    The first element of a Python list has index
    _____
    .
    Hint

    Python uses the same starting index for strings and lists.

    Answer

    zero

    Explanation

    List indexes are zero-based, so the first element is at position zero.

  60. 60
    In a list, an index of negative one accesses the
    _____
    element.
    Hint

    Negative indexes count from the end of the list.

    Answer

    last

    Explanation

    A negative one index selects the last element, while other negative indexes move backward from it.

  61. 61
    A list slice with a start and stop index includes the start but does not include the
    _____
    index.
    Hint

    The ending boundary is excluded from the selected slice.

    Answer

    stop

    Explanation

    Python list slicing includes the starting index and stops before the specified ending index.

  62. 62
    A list element can be changed by assigning a new value at its
    _____
    .
    Hint

    The position identifies which item to update.

    Answer

    index

    Explanation

    Lists are mutable, so a program can assign a new value to an element at a chosen index.

  63. 63
    The list method that adds another list's elements to the end of a list is
    _____
    .
    Hint

    It takes a collection of additional items.

    Answer

    extend

    Explanation

    The extend method appends the elements of another iterable, such as a list, to the current list.

  64. 64
    The list method that adds one element to the end of a list is
    _____
    .
    Hint

    Unlike extend, it adds a single item.

    Answer

    append

    Explanation

    The append method adds one element at the end of a list.

  65. 65
    The list method that inserts an element at a chosen position is
    _____
    .
    Hint

    It takes an index and the new element.

    Answer

    insert

    Explanation

    The insert method places an element at a specified index and shifts later elements to make room.

  66. 66
    The list method that removes a specified matching value is
    _____
    .
    Hint

    It identifies the item by its value rather than its position.

    Answer

    remove

    Explanation

    The remove method removes the specified value from a list.

  67. 67
    The list method that empties a list by removing all of its elements is
    _____
    .
    Hint

    It resets the list to an empty state.

    Answer

    clear

    Explanation

    The clear method removes every element from the list.

  68. 68
    The list method that removes and returns the last element by default is
    _____
    .
    Hint

    Its name suggests taking an item off the list.

    Answer

    pop

    Explanation

    The pop method removes the last element from a list by default and returns that element.

  69. 69
    The list method that returns the position of a specified value is
    _____
    .
    Hint

    It can be used to check where a value such as a friend's name appears.

    Answer

    index

    Explanation

    The index method returns the index of a value in a list and raises an error if the value is absent.

  70. 70
    The list method that counts how many times a value occurs is
    _____
    .
    Hint

    It is useful when the same value appears more than once.

    Answer

    count

    Explanation

    The count method returns the number of occurrences of a specified value in a list.

  71. 71
    The list method that orders items into ascending order is
    _____
    .
    Hint

    For text, this can arrange names alphabetically.

    Answer

    sort

    Explanation

    The sort method orders a list's elements in ascending order.

  72. 72
    The list method that reverses the current order of elements is
    _____
    .
    Hint

    The first item becomes last and the last becomes first.

    Answer

    reverse

    Explanation

    The reverse method reverses the order of elements in a list.

  73. 73
    The list method that creates a shallow copy of a list is
    _____
    .
    Hint

    It provides a separate list containing the same elements.

    Answer

    copy

    Explanation

    The copy method creates a copy of a list's contents.

  74. 74
    A tuple differs from a list because a tuple is
    _____
    after it is created.
    Hint

    Its elements cannot be changed, added, or removed.

    Answer

    immutable

    Explanation

    Tuples are immutable, whereas lists can be modified after creation.

  75. 75
    A tuple is typically created using parentheses and stores multiple
    _____
    .
    Hint

    Coordinates are one example of the data tuples can hold.

    Answer

    values

    Explanation

    Tuples are containers for multiple values, commonly used when the stored data should not change.

  76. 76
    A Python dictionary stores data in
    _____
    value pairs.
    Hint

    Each identifying label is associated with corresponding data.

    Answer

    key

    Explanation

    A dictionary organizes information as key-value pairs.

  77. 77
    The keys in a dictionary must be
    _____
    so that each entry can be identified distinctly.
    Hint

    Duplicate keys are identified as a problem in the example.

    Answer

    unique

    Explanation

    Dictionary keys should be unique; the example warns that duplicate keys are not allowed.

  78. 78
    A dictionary literal is enclosed in curly
    _____
    .
    Hint

    These delimiters surround its key-value entries.

    Answer

    brackets

    Explanation

    Python uses curly brackets to create a dictionary literal.

  79. 79
    The dictionary method that retrieves a value by key and can provide a fallback is
    _____
    .
    Hint

    It can return a default when the requested key is missing.

    Answer

    get

    Explanation

    The get method retrieves a key's value and can return a specified default if that key is absent.

  80. 80
    A function is a reusable collection of code that performs a specific
    _____
    .
    Hint

    It groups instructions that work together to accomplish something.

    Answer

    task

    Explanation

    Functions organize code into reusable units, each designed to perform a particular task.

  81. 81
    The keyword used to define a function in Python is
    _____
    .
    Hint

    It appears before the function name in a definition.

    Answer

    def

    Explanation

    A Python function definition begins with the keyword def.

  82. 82
    A function's indented code does not run until the function is
    _____
    .
    Hint

    This means requesting that the function execute.

    Answer

    called

    Explanation

    Defining a function does not execute its body; the function runs when it is called.

  83. 83
    Information supplied to a function when it is called can be received through
    _____
    .
    Hint

    A name and age can be passed into a greeting function this way.

    Answer

    parameters

    Explanation

    Parameters let a function receive values and use them when performing its task.

  84. 84
    The keyword that sends a value back from a function is
    _____
    .
    Hint

    It can provide the result of a calculation to the caller.

    Answer

    return

    Explanation

    The return statement gives a value back to the code that called the function.

  85. 85
    After a function executes a return statement, it immediately exits that
    _____
    .
    Hint

    Code later in the same function body is not reached.

    Answer

    function

    Explanation

    A return statement ends the current function, so subsequent statements in its body do not run.

  86. 86
    The statement that lets a program execute code only when a condition is true is an
    _____
    statement.
    Hint

    It introduces a conditional branch.

    Answer

    if

    Explanation

    An if statement checks a condition and runs its indented block when that condition is true.

  87. 87
    The keyword that provides a fallback branch when an if condition is false is
    _____
    .
    Hint

    It corresponds to the idea of 'otherwise.'

    Answer

    else

    Explanation

    An else block runs when the preceding if condition is false and no earlier alternative condition matched.

  88. 88
    The Python keyword for checking another condition after an earlier if condition fails is
    _____
    .
    Hint

    It combines the ideas of 'else' and 'if.'

    Answer

    elif

    Explanation

    An elif branch allows a program to test another condition when the preceding if condition is false.

  89. 89
    The logical operator that makes a condition true when at least one of two conditions is true is
    _____
    .
    Hint

    It allows either condition to satisfy the branch.

    Answer

    or

    Explanation

    The or operator evaluates as true when either operand, or both operands, are true.

  90. 90
    The logical operator that requires both conditions to be true is
    _____
    .
    Hint

    It combines two requirements that must both hold.

    Answer

    and

    Explanation

    The and operator evaluates as true only when both conditions are true.

  91. 91
    The operator that reverses a Boolean condition is
    _____
    .
    Hint

    It turns true into false and false into true.

    Answer

    not

    Explanation

    The not operator negates the truth value of the expression that follows it.

  92. 92
    The comparison operator made from two equals signs checks whether two values are
    _____
    .
    Hint

    Do not confuse it with the single assignment symbol.

    Answer

    equal

    Explanation

    The double-equals comparison checks equality; a single equals sign assigns a value.

  93. 93
    The comparison operator made from an exclamation point followed by an equals sign checks whether values are
    _____
    .
    Hint

    It tests whether two values differ.

    Answer

    not equal

    Explanation

    This comparison returns true when the two values are different.

  94. 94
    A calculator program can use comparisons and if statements to select which arithmetic
    _____
    to perform.
    Hint

    The user's operator choice determines whether to add, subtract, multiply, or divide.

    Answer

    operation

    Explanation

    The calculator checks the selected operator and carries out the corresponding arithmetic operation.

  95. 95
    A while loop repeats its indented block as long as its condition remains
    _____
    .
    Hint

    The loop stops when its condition no longer holds.

    Answer

    true

    Explanation

    A while loop checks its condition and repeats the body while that condition is true.

  96. 96
    The condition controlling whether a while loop continues is also called its loop
    _____
    .
    Hint

    It protects the loop from continuing once its condition fails.

    Answer

    guard

    Explanation

    The course also calls a loop condition a loop guard; the loop repeats while that guard is true.

  97. 97
    In a guessing game, a while loop can continue prompting the user until the guess matches the
    _____
    word.
    Hint

    The program stores this target value before the guessing begins.

    Answer

    secret

    Explanation

    The guessing game repeats until the user's guess equals the stored secret word.

  98. 98
    To limit a guessing game, the program can track a guess count and compare it with a guess
    _____
    .
    Hint

    This value sets the maximum number of attempts.

    Answer

    limit

    Explanation

    The game can stop accepting guesses after the count reaches the specified limit.

  99. 99
    A for loop is designed to iterate over a collection or a range of
    _____
    .
    Hint

    Examples include letters in a string or values in a list.

    Answer

    items

    Explanation

    For loops process each item in a collection, or each value in a specified range.

  100. 100
    In a for loop over a string, the loop variable can represent one
    _____
    on each iteration.
    Hint

    The example processes the characters in a phrase one at a time.

    Answer

    letter

    Explanation

    When a for loop iterates over a string, its loop variable takes each character in turn.

  101. 101
    A range ending at a specified number does not include that ending
    _____
    .
    Hint

    A range from zero to ten includes zero through nine.

    Answer

    number

    Explanation

    The upper bound of a Python range is excluded from the sequence it produces.

  102. 102
    The built-in function that reports how many elements are in a list is
    _____
    .
    Hint

    It can be combined with range to iterate over list indexes.

    Answer

    len

    Explanation

    The len function returns the number of elements in a list.

  103. 103
    A loop placed inside another loop is a
    _____
    loop.
    Hint

    The inner loop runs within the body of the outer loop.

    Answer

    nested

    Explanation

    Nested loops are useful for processing structures such as rows and columns in a two-dimensional list.

  104. 104
    A list whose elements are themselves lists can represent a two-dimensional
    _____
    .
    Hint

    Rows and columns provide a useful way to visualize its elements.

    Answer

    grid

    Explanation

    A two-dimensional list can hold lists of values, forming a grid of rows and columns.

  105. 105
    A try block contains code that Python should attempt to
    _____
    .
    Hint

    An except block can handle a problem that happens while it runs.

    Answer

    execute

    Explanation

    The try part of a try-except structure contains code that may raise an error.

  106. 106
    A try-except structure prevents an unhandled error from automatically stopping the entire
    _____
    .
    Hint

    It lets the code respond to selected error situations.

    Answer

    program

    Explanation

    An except block can handle an error and allow the program to respond instead of simply terminating.

  107. 107
    Catching a specific exception is preferable to using a broad
    _____
    clause.
    Hint

    A catch-all can mistakenly handle unrelated problems.

    Answer

    exception

    Explanation

    The tutorial recommends catching specific error types because a broad except clause may hide unrelated errors.

  108. 108
    The exception raised when attempting to divide a number by zero is a zero division
    _____
    .
    Hint

    It names the invalid arithmetic operation.

    Answer

    error

    Explanation

    Python raises a ZeroDivisionError for a division-by-zero operation.

  109. 109
    When a user enters text where an integer is expected, converting it can raise a value
    _____
    .
    Hint

    The conversion fails because the input is not a valid integer.

    Answer

    error

    Explanation

    An invalid value supplied to int can raise a ValueError, which can be handled with an except block.

  110. 110
    The function used to open an external file is
    _____
    .
    Hint

    It takes a file name and a mode.

    Answer

    open

    Explanation

    The open function opens an external file so the program can read or write it.

  111. 111
    The file mode that allows a program to read a file without changing it is
    _____
    .
    Hint

    It is the mode used to retrieve the file's existing contents.

    Answer

    read

    Explanation

    Read mode gives access to a file's contents without writing changes to it.

  112. 112
    The file mode that adds new content to the end of an existing file is
    _____
    .
    Hint

    It preserves existing content and adds more after it.

    Answer

    append

    Explanation

    Append mode adds content to the end of the file rather than replacing its existing contents.

  113. 113
    Opening a file in write mode can
    _____
    its existing contents.
    Hint

    This mode is useful for writing a new file but can erase old content.

    Answer

    overwrite

    Explanation

    Write mode replaces the existing file contents, or creates a file if one does not exist.

  114. 114
    After finishing work with an opened file, good practice is to
    _____
    it.
    Hint

    This releases the file resource when it is no longer needed.

    Answer

    close

    Explanation

    The tutorial recommends closing a file after the program is done using it.

  115. 115
    The file method that reads the entire contents of a file is
    _____
    .
    Hint

    It returns the file's content as a whole.

    Answer

    read

    Explanation

    The read method retrieves all of the file's contents.

  116. 116
    The file method that reads a single line at a time is
    _____
    .
    Hint

    Repeated calls can advance to later lines.

    Answer

    readline

    Explanation

    The readline method reads one line from the file on each call.

  117. 117
    The file method that returns file lines as a list is
    _____
    .
    Hint

    Each line becomes an item that can be processed in a loop.

    Answer

    readlines

    Explanation

    The readlines method places the lines of a file into a list.

  118. 118
    The file method that writes supplied text to a file is
    _____
    .
    Hint

    Its effect depends on whether the file was opened in write or append mode.

    Answer

    write

    Explanation

    The write method adds the supplied text to a file, according to its opening mode.

  119. 119
    The escape sequence used to put appended text on a new line is backslash followed by
    _____
    .
    Hint

    It is the same line-break sequence used in strings.

    Answer

    n

    Explanation

    The backslash n escape sequence inserts a line break before appended text.

  120. 120
    A Python module is an external Python
    _____
    that can be imported into another file.
    Hint

    It can contain functions, variables, and other reusable code.

    Answer

    file

    Explanation

    A module is a Python file whose functionality can be imported into another Python file.

  121. 121
    The statement used to make another module's functionality available is
    _____
    .
    Hint

    It commonly appears at the beginning of a Python file.

    Answer

    import

    Explanation

    Importing a module lets a program use functions, variables, and other definitions from that module.

  122. 122
    A module that comes with Python rather than being installed separately is a
    _____
    module.
    Hint

    Its functionality is included with the language installation.

    Answer

    built-in

    Explanation

    Built-in modules are included with Python, unlike third-party modules that may need separate installation.

  123. 123
    A third-party module can commonly be installed from the command line with
    _____
    .
    Hint

    It is Python's package manager.

    Answer

    pip

    Explanation

    pip is commonly used to install third-party Python modules from the command line.

  124. 124
    The folder commonly used for installed third-party Python packages is called site
    _____
    .
    Hint

    The folder name describes where add-on packages are kept.

    Answer

    packages

    Explanation

    The tutorial identifies site packages as the folder where pip-installed third-party modules are commonly placed.

  125. 125
    A class can define a new data
    _____
    for representing an entity such as a student.
    Hint

    It extends the basic built-in categories such as strings and numbers.

    Answer

    type

    Explanation

    Classes let programmers create custom data types that can model real-world entities.

  126. 126
    A class describes a template, while an individual instance of that class is an
    _____
    .
    Hint

    A particular student with an actual name and GPA is one example.

    Answer

    object

    Explanation

    A class defines the structure, and an object is a specific instance with concrete attribute values.

  127. 127
    Data associated with an object, such as a student's name or GPA, is stored in its
    _____
    .
    Hint

    These describe the object's properties.

    Answer

    attributes

    Explanation

    Attributes hold information about an object, such as a student's name, major, GPA, or probation status.

  128. 128
    The special initialization method used to set up a newly created object is
    _____
    .
    Hint

    It is automatically involved when an object is created.

    Answer

    init

    Explanation

    The initialization method assigns the values supplied when an object is created to its attributes.

  129. 129
    In an instance method, the first parameter conventionally used to refer to the current object is
    _____
    .
    Hint

    It lets the method access that object's attributes.

    Answer

    self

    Explanation

    The self parameter refers to the current instance, such as when accessing its GPA.

  130. 130
    A function defined inside a class and used by its objects is a class
    _____
    .
    Hint

    It can provide a service such as checking whether a student meets a condition.

    Answer

    function

    Explanation

    A function defined in a class can operate on its objects or provide information about them.

  131. 131
    Inheritance lets one class reuse attributes and functions from another
    _____
    .
    Hint

    A specialized chef can reuse capabilities defined for a general chef.

    Answer

    class

    Explanation

    Inheritance allows a class to obtain functionality from a parent class without rewriting it.

  132. 132
    A class that inherits functionality from another class is often called a
    _____
    class.
    Hint

    It is the more specialized class in the relationship.

    Answer

    child

    Explanation

    A child class can inherit functionality from a parent class and add specialized behavior.

  133. 133
    A class whose functionality is inherited by another class is often called a
    _____
    class.
    Hint

    It is the more general class in the relationship.

    Answer

    parent

    Explanation

    A parent class provides attributes and methods that an inheriting child class can use.

  134. 134
    Defining a method in a child class with the same role as an inherited method lets it
    _____
    the parent's behavior.
    Hint

    A Chinese chef can provide a different special dish from a generic chef.

    Answer

    override

    Explanation

    A child class can override an inherited method to provide its own specialized behavior.

  135. 135
    A multiple-choice quiz can model each question using a class that stores its prompt and
    _____
    .
    Hint

    Both are needed to ask and grade a question.

    Answer

    answer

    Explanation

    The quiz example creates a question data type with a prompt attribute and an answer attribute.

  136. 136
    The Python interpreter provides an interactive environment for quickly testing Python
    _____
    .
    Hint

    It is useful for short experiments without creating a source file.

    Answer

    commands

    Explanation

    The interpreter executes entered Python commands immediately, making it useful for quick tests.

  137. 137
    The terminal or command prompt allows interaction with a computer by entering text
    _____
    .
    Hint

    It is an alternative to interacting through graphical buttons and windows.

    Answer

    commands

    Explanation

    A terminal or command prompt provides a text-based way to interact with the computer.

  138. 138
    The interpreter is suited to quick experiments, while a text editor is better for writing a complete Python
    _____
    .
    Hint

    A larger piece of code is easier to organize in a source file.

    Answer

    program

    Explanation

    The interpreter is convenient for small tests, but a text editor is more organized for building full programs.

1 of 138
Question 1 of 138

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent