1. Home
  2. Explore
  3. Computer Science
  4. Python for Data Analysis

Study methods

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

Python for Data Analysis

  • 142Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Python Foundations

What does computer programming mean?

142 questions

  1. 1

    What does computer programming mean?

    1. A

      The process of giving a computer instructions to perform actions

    2. B

      The process of converting every program into a spreadsheet

    3. C

      The process of storing computer hardware in an organized format

    4. D

      The process of connecting computers to a shared network

    Correct answer
    A

    The process of giving a computer instructions to perform actions

    Explanation

    Programming is the process of giving a computer instructions to perform actions. A programming language provides a way to write those instructions.

  2. 2

    Why are transistors relevant to the way computers process instructions?

    1. A

      They translate spoken language directly into computer instructions

    2. B

      They store high-level programming syntax as text

    3. C

      They organize program files into reusable libraries

    4. D

      They control electrical flow through on and off states

    Correct answer
    D

    They control electrical flow through on and off states

    Explanation

    Transistors act like switches that control electrical flow. Their on and off states correspond to binary values, which underpin how computers represent instructions.

  3. 3

    What does binary represent in the explanation of computer operation?

    1. A

      It represents the sequence of steps in a for loop

    2. B

      It represents on and off states using ones and zeros

    3. C

      It describes the rules for naming variables in Python

    4. D

      It stores data using rows and columns

    Correct answer
    B

    It represents on and off states using ones and zeros

    Explanation

    Binary represents the on and off states of transistors using ones and zeros. Computers ultimately operate on these binary representations.

  4. 4

    Which description best characterizes early low-level programming languages?

    1. A

      They are written primarily to organize tabular data

    2. B

      They use familiar syntax and work across many types of tasks

    3. C

      They were difficult to use and often machine-specific

    4. D

      They are libraries that contain reusable mathematical functions

    Correct answer
    C

    They were difficult to use and often machine-specific

    Explanation

    Low-level languages were difficult to use, required extensive training, and often worked only on the machine for which they were designed.

  5. 5

    What is a defining feature of a high-level programming language?

    1. A

      They communicate with hardware only through electrical signals

    2. B

      They are limited to controlling a computer's transistors

    3. C

      They use more human-friendly syntax and structures

    4. D

      They can only be used to write data visualization programs

    Correct answer
    C

    They use more human-friendly syntax and structures

    Explanation

    High-level languages use syntax designed to be more familiar to humans than binary or low-level instructions.

  6. 6

    Which statement best describes Python?

    1. A

      It requires users to write all common functions from scratch

    2. B

      It is a low-level language designed for one specific machine

    3. C

      It is a versatile, approachable, powerful high-level language

    4. D

      It is limited to writing instructions for web browsers

    Correct answer
    C

    It is a versatile, approachable, powerful high-level language

    Explanation

    Python is presented as a versatile, approachable, powerful high-level language. Its open-source ecosystem also includes many libraries and tools.

  7. 7

    What is a Python library?

    1. A

      A single value stored in a variable's memory location

    2. B

      A sequence of instructions that can only run once

    3. C

      A reusable collection of code for common or specialized tasks

    4. D

      A rule that determines the order of arithmetic operations

    Correct answer
    C

    A reusable collection of code for common or specialized tasks

    Explanation

    A library is a reusable collection of code. Using an existing library can save time compared with writing common functionality yourself.

  8. 8

    Which set of tasks is described as part of Python's role in data work?

    1. A

      It replaces the need to inspect or clean data

    2. B

      It is used only to enter data into spreadsheets

    3. C

      It is used only to create machine learning models

    4. D

      It supports tasks from data exploration through model building

    Correct answer
    D

    It supports tasks from data exploration through model building

    Explanation

    Python can support many stages of data work, including exploration, cleaning, visualization, and machine learning model development.

  9. 9

    What is a Jupyter Notebook?

    1. A

      A Python data type that stores rows and columns

    2. B

      A terminal command that runs a program line by line without editing

    3. C

      An open-source web application combining code, text, and outputs

    4. D

      A library used exclusively to generate random numbers

    Correct answer
    C

    An open-source web application combining code, text, and outputs

    Explanation

    A Jupyter Notebook is an open-source web application for documents that can combine live code, text, mathematical formulas, and visualizations.

  10. 10

    What is a practical advantage of organizing notebook work into cells?

    1. A

      They prevent users from changing or rearranging code

    2. B

      They convert every code statement into a spreadsheet row

    3. C

      They force every instruction to run only once in a fixed order

    4. D

      They divide notebook content into modular input/output fields

    Correct answer
    D

    They divide notebook content into modular input/output fields

    Explanation

    Notebook cells make it easier to organize code into modules or sections, move or remove code, and keep output and explanations together.

  11. 11

    What role does Markdown play in a Jupyter Notebook?

    1. A

      It is a method that sorts a list from least to greatest

    2. B

      It lets users add formatted explanatory text in a coding environment

    3. C

      It is a data structure that stores unique, unordered values

    4. D

      It is the Python command for changing a variable's data type

    Correct answer
    B

    It lets users add formatted explanatory text in a coding environment

    Explanation

    Markdown is a way to write formatted text in a coding environment, including elements such as headings, bullets, tables, and formulas.

  12. 12

    What is the central idea of object-oriented programming?

    1. A

      It organizes data together with code that operates on it

    2. B

      It stores all program data in one global variable

    3. C

      It prevents functions from acting on stored data

    4. D

      It organizes programs only as sequences of arithmetic operators

    Correct answer
    A

    It organizes data together with code that operates on it

    Explanation

    Object-oriented programming organizes code around objects that can contain data and methods that manipulate that data.

  13. 13

    Which explanation best describes a Python variable?

    1. A

      A variable is the memory location itself and cannot refer to a value

    2. B

      A variable is a Python function that prints a value

    3. C

      A variable is a fixed data type that cannot be reassigned

    4. D

      A variable is a name that refers to a value stored in memory

    Correct answer
    D

    A variable is a name that refers to a value stored in memory

    Explanation

    A variable is a name that points to a value stored in memory; it is not the value itself.

  14. 14

    What does a data type describe?

    1. A

      A label used only to identify the creator of a program

    2. B

      A process that repeatedly executes a block of code

    3. C

      A description of data based on its values or possible operations

    4. D

      A rule for arranging lines of code in a notebook

    Correct answer
    C

    A description of data based on its values or possible operations

    Explanation

    A data type describes data in terms of its values, language representation, or the operations it can perform.

  15. 15

    What does dynamic typing mean in Python?

    1. A

      A variable's data type is permanently fixed at its first assignment

    2. B

      A variable must be declared with its type before any assignment

    3. C

      A variable can refer only to strings and integers

    4. D

      A variable can refer to objects of different data types

    Correct answer
    D

    A variable can refer to objects of different data types

    Explanation

    Python uses dynamic typing: a variable can refer to objects of different data types as it is reassigned.

  16. 16

    Why should a variable be initialized before it is used?

    1. A

      Variables must be initialized with a Boolean value

    2. B

      Variables can be called before their names are assigned

    3. C

      A variable generally needs a value assigned before it is called

    4. D

      Variables are initialized automatically as empty strings

    Correct answer
    C

    A variable generally needs a value assigned before it is called

    Explanation

    Most variables need an initial assignment before they can be used. That first assignment is often called initialization.

  17. 17

    Why is a descriptive variable name generally preferable to a vague name?

    1. A

      Names should always match the name of a built-in function

    2. B

      Names should be as short as possible, even if their meaning is unclear

    3. C

      Names should help readers understand the value or purpose stored

    4. D

      Names should indicate only the programming language being used

    Correct answer
    C

    Names should help readers understand the value or purpose stored

    Explanation

    A meaningful name such as age_list communicates the contents more clearly than a vague name such as x.

  18. 18

    Which comparison correctly distinguishes an assignment from an expression?

    1. A

      An assignment converts strings; an expression prevents reassignment

    2. B

      An assignment creates a loop; an expression names a variable

    3. C

      An assignment stores a value; an expression evaluates to a result

    4. D

      An assignment compares two values; an expression stores a function

    Correct answer
    C

    An assignment stores a value; an expression evaluates to a result

    Explanation

    An assignment stores a value in a variable. An expression combines values, symbols, or variables to produce a result when evaluated.

  19. 19

    How do integers and floats differ?

    1. A

      Integers represent decimal numbers; floats represent whole numbers

    2. B

      Integers store text; floats store only Boolean values

    3. C

      Integers and floats both represent sequences of characters

    4. D

      Integers represent whole numbers; floats represent decimal numbers

    Correct answer
    D

    Integers represent whole numbers; floats represent decimal numbers

    Explanation

    Integers represent whole numbers without fractions, while floats represent numbers with decimal components.

  20. 20

    What is a string?

    1. A

      Strings are whole numbers that cannot contain a decimal point

    2. B

      Strings are sequences of characters used to represent text

    3. C

      Strings are Boolean expressions that evaluate to true or false

    4. D

      Strings are ordered collections of numeric values without punctuation

    Correct answer
    B

    Strings are sequences of characters used to represent text

    Explanation

    Strings are sequences of characters and punctuation used to represent textual information. They are typically written within quotation marks.

  21. 21

    What does it mean that strings are immutable?

    1. A

      Strings can be modified only if they contain numbers

    2. B

      Strings can be changed in place, but only by using a loop

    3. C

      Strings cannot be combined with other strings

    4. D

      Strings cannot be changed in place; a changed value must be reassigned

    Correct answer
    D

    Strings cannot be changed in place; a changed value must be reassigned

    Explanation

    Strings are immutable: their characters cannot be changed in place. A modified string must be assigned as a new value to a variable.

  22. 22

    What does the Python type function do?

    1. A

      It returns the number of elements in an object

    2. B

      It checks whether one value is greater than another

    3. C

      It reports the data type of an object

    4. D

      It converts any object into a string

    Correct answer
    C

    It reports the data type of an object

    Explanation

    Python's type function identifies an object's type, such as str, int, or float.

  23. 23

    Which situation is an example of implicit type conversion?

    1. A

      A variable is renamed without changing its stored value

    2. B

      The interpreter automatically converts a value to another type

    3. C

      A string is split into individual characters

    4. D

      The programmer explicitly calls int, float, or str

    Correct answer
    B

    The interpreter automatically converts a value to another type

    Explanation

    Implicit conversion happens automatically without the programmer explicitly requesting a type conversion. For example, mixed integer and float arithmetic can convert the integer to a float.

  24. 24

    What is explicit type conversion?

    1. A

      A function returns multiple values in a tuple

    2. B

      The interpreter changes a type without any instruction from the user

    3. C

      A variable is overwritten with a value of the same type

    4. D

      The programmer uses a conversion function to request a new type

    Correct answer
    D

    The programmer uses a conversion function to request a new type

    Explanation

    Explicit conversion, also called typecasting, uses functions such as int, float, or str to convert an object to a specified type.

  25. 25

    How do the operators = and == differ in Python?

    1. A

      A single equals sign assigns values; two equals signs test equality

    2. B

      Both forms compare values, but the single form compares types

    3. C

      A single equals sign compares values; two equals signs assign values

    4. D

      Both forms assign values, but the second is used for strings

    Correct answer
    A

    A single equals sign assigns values; two equals signs test equality

    Explanation

    A single equals sign assigns a value, while two equals signs compare values for equality.

  26. 26

    Why should a Python keyword not be used as a variable name?

    1. A

      Keywords are names for values returned by functions

    2. B

      Keywords are valid variable names if written in lowercase

    3. C

      Keywords are user-created labels for data structures

    4. D

      Keywords are reserved for specific language purposes

    Correct answer
    D

    Keywords are reserved for specific language purposes

    Explanation

    Python treats keywords such as if, for, and else as reserved words with specific language purposes, so they should not be used as variable names.

  27. 27

    Which rule applies to Python variable names?

    1. A

      A name may use any punctuation if it begins with a letter

    2. B

      A name must start with a number and cannot contain underscores

    3. C

      A name may contain spaces if each word starts with a capital letter

    4. D

      A name may use letters, numbers, and underscores, but cannot start with a number

    Correct answer
    D

    A name may use letters, numbers, and underscores, but cannot start with a number

    Explanation

    Variable names can contain letters, numbers, and underscores, but must start with a letter or underscore and cannot contain spaces or special characters such as ampersands.

  28. 28

    What does it mean that Python is case-sensitive?

    1. A

      Capitalization matters only for names of functions

    2. B

      Capitalization is ignored for all variable names

    3. C

      Names that differ only by capitalization are treated as different

    4. D

      Capitalization matters only when a name contains numbers

    Correct answer
    C

    Names that differ only by capitalization are treated as different

    Explanation

    Python is case-sensitive, so capitalization changes the spelling of an identifier and may make it refer to a different name.

  29. 29

    How do methods and attributes differ?

    1. A

      A method performs an operation; an attribute stores an associated value

    2. B

      A method names a class; an attribute converts one class into another

    3. C

      A method is a value without behavior; an attribute is a reusable function

    4. D

      A method belongs only to a notebook; an attribute belongs only to a list

    Correct answer
    A

    A method performs an operation; an attribute stores an associated value

    Explanation

    A method is a function associated with a class. It typically performs an operation on an object, while an attribute represents an associated value or characteristic.

  30. 30

    What is dot notation used for in Python?

    1. A

      It assigns a new value using a single equals sign

    2. B

      It indicates the start of a comment in a Python script

    3. C

      It separates keys from values in a dictionary

    4. D

      It accesses methods or attributes attached to an object

    Correct answer
    D

    It accesses methods or attributes attached to an object

    Explanation

    Dot notation accesses methods and attributes associated with an object, as in object.method() or object.attribute.

  31. 31

    Which statement describes a user-defined Python function?

    1. A

      A reusable block of code defined with the def keyword

    2. B

      A data type that stores an ordered collection of values

    3. C

      A value that can be stored only in a dictionary

    4. D

      A comment that is executed each time a program runs

    Correct answer
    A

    A reusable block of code defined with the def keyword

    Explanation

    A function is reusable code for performing a task. A function definition begins with the def keyword and includes a name and, optionally, parameters.

  32. 32

    Which statement correctly distinguishes function parameters from arguments?

    1. A

      Parameters and arguments are both values returned by a function

    2. B

      Parameters are comments; arguments are the function's indented body

    3. C

      Parameters are supplied when calling a function; arguments are written only in its definition

    4. D

      Parameters are names in the definition; arguments are values passed to the function

    Correct answer
    D

    Parameters are names in the definition; arguments are values passed to the function

    Explanation

    Parameters are the names in a function definition; arguments are the actual values or information supplied when the function is called.

  33. 33

    How is a function body indicated in Python?

    1. A

      The function body is written only after the function is called

    2. B

      The function body must use a different indentation on every line

    3. C

      The function body is indented beneath the function definition

    4. D

      The function body must be placed before the def line

    Correct answer
    C

    The function body is indented beneath the function definition

    Explanation

    The function body contains the instructions to execute and is indented beneath the function definition. Consistent indentation makes the code structure clear.

  34. 34

    What is the key role of return in a function?

    1. A

      It displays a message but prevents the value from being reused

    2. B

      It changes every argument into a string

    3. C

      It provides a result that can be stored or used elsewhere

    4. D

      It repeats the function body until a condition changes

    Correct answer
    C

    It provides a result that can be stored or used elsewhere

    Explanation

    A return statement gives a value back from a function, allowing that value to be stored or used in later calculations rather than merely printed.

  35. 35

    Why is a return value useful when writing reusable code?

    1. A

      Returned values are printed automatically and cannot be stored

    2. B

      Returning a value prevents a function from being called again

    3. C

      Returned values can be assigned and combined with later operations

    4. D

      A returned value can be used only as a function argument

    Correct answer
    C

    Returned values can be assigned and combined with later operations

    Explanation

    A function that returns values can be composed with other operations. For example, separate function results can be stored and then added together.

  36. 36

    What does code reusability mean?

    1. A

      Defining code once and using it repeatedly

    2. B

      Combining all program instructions into one long statement

    3. C

      Using code only once and then deleting it

    4. D

      Writing a new copy of the same code for every input

    Correct answer
    A

    Defining code once and using it repeatedly

    Explanation

    Reusability means defining code once and using it multiple times, rather than rewriting the same logic for each use.

  37. 37

    What is modularity in programming?

    1. A

      Changing code structure without preserving its behavior

    2. B

      Converting every function into a global variable

    3. C

      Dividing code into components that work together and can be reused

    4. D

      Writing all code in a single block to avoid dependencies

    Correct answer
    C

    Dividing code into components that work together and can be reused

    Explanation

    Modularity means writing code in separate components that can work together and be reused in other programs.

  38. 38

    What is refactoring?

    1. A

      Converting a reusable function into a comment

    2. B

      Removing a program's outputs while keeping its inputs

    3. C

      Restructuring code while preserving its functionality

    4. D

      Changing a function's purpose while retaining its name

    Correct answer
    C

    Restructuring code while preserving its functionality

    Explanation

    Refactoring restructures code while preserving its original functionality. It can make code clearer without changing what it does.

  39. 39

    What is self-documenting code?

    1. A

      Code whose names and structure make its purpose understandable

    2. B

      Code that requires a separate explanation for every line

    3. C

      Code that contains no variable names or expressions

    4. D

      Code that runs only when every statement is commented out

    Correct answer
    A

    Code whose names and structure make its purpose understandable

    Explanation

    Self-documenting code is written so that its purpose is clear from its structure, names, and expressions. Comments can supplement that clarity.

  40. 40

    How does Python treat a line that begins with #?

    1. A

      A comment begins with a colon and defines a function

    2. B

      A comment begins with two equals signs and tests a condition

    3. C

      A comment begins with # and is ignored by Python execution

    4. D

      A comment begins with parentheses and returns a value

    Correct answer
    C

    A comment begins with # and is ignored by Python execution

    Explanation

    A comment begins with the # character, and Python ignores the remainder of that line when executing the program.

  41. 41

    What is a function docstring used for?

    1. A

      A string placed after a function call to change its output

    2. B

      A variable that stores every comment in a program

    3. C

      A string at the start of a function that documents its behavior

    4. D

      A reserved keyword that causes a function to repeat

    Correct answer
    C

    A string at the start of a function that documents its behavior

    Explanation

    A docstring is a string at the beginning of a function body that summarizes its behavior and explains its arguments and return values.

  42. 42

    What is an algorithm?

    1. A

      A rule that says how many spaces must follow a comment

    2. B

      A reusable library that contains programming languages

    3. C

      A collection of data values stored in a table

    4. D

      A set of instructions for solving a problem or task

    Correct answer
    D

    A set of instructions for solving a problem or task

    Explanation

    An algorithm is a set of instructions for solving a problem or accomplishing a task. A recipe is an everyday example of an algorithm.

  43. 43

    How can comments help when developing a function for a complex task?

    1. A

      They guarantee that a function will return a correct value

    2. B

      They execute each planned step automatically

    3. C

      They can provide a step-by-step scaffold for planning code

    4. D

      They convert a complex problem into a data type

    Correct answer
    C

    They can provide a step-by-step scaffold for planning code

    Explanation

    Comments can outline the stages of a solution before the code is written, helping break a problem into manageable steps.

  44. 44

    Which set lists Python's six comparison operators described in the content?

    1. A

      Greater than, greater than or equal to, less than, less than or equal to, equal, and not equal

    2. B

      Append, insert, remove, pop, sort, and reverse

    3. C

      And, or, not, in, is, and return

    4. D

      Add, subtract, multiply, divide, exponentiate, and assign

    Correct answer
    A

    Greater than, greater than or equal to, less than, less than or equal to, equal, and not equal

    Explanation

    The six comparisons described are greater than, greater than or equal to, less than, less than or equal to, equal to, and not equal to.

  45. 45

    What do comparator operators produce?

    1. A

      They combine separate functions into a single library

    2. B

      They compare values and produce Boolean results

    3. C

      They convert numerical values into strings

    4. D

      They repeat a block until a process is complete

    Correct answer
    B

    They compare values and produce Boolean results

    Explanation

    Comparators compare two values and produce Boolean results, such as True or False.

  46. 46

    When does an and expression evaluate to True?

    1. A

      True whenever at least one expression is True

    2. B

      True whenever the expressions have different data types

    3. C

      True only when both expressions are True

    4. D

      True only when both expressions are False

    Correct answer
    C

    True only when both expressions are True

    Explanation

    The and operator returns True only when both expressions are True. If either expression is False, the combined result is False.

  47. 47

    When does an or expression evaluate to True?

    1. A

      Only when both of its expressions are False

    2. B

      When at least one of its expressions is True

    3. C

      When the two expressions have the same value

    4. D

      Only when both of its expressions are True

    Correct answer
    B

    When at least one of its expressions is True

    Explanation

    An or expression is True if either expression is True, and is False only if both expressions are False.

  48. 48

    What does the logical operator not do?

    1. A

      It compares the expression with a string

    2. B

      It combines the expression with the next statement using and

    3. C

      It reverses the expression's Boolean value

    4. D

      It repeats the expression until it becomes True

    Correct answer
    C

    It reverses the expression's Boolean value

    Explanation

    The not operator inverts the Boolean value of the expression that follows it: True becomes False and False becomes True.

  49. 49

    How are two strings compared when their first characters match?

    1. A

      It compares the number of spaces in each string

    2. B

      It compares the strings' lengths before comparing their characters

    3. C

      It compares characters in sequence, proceeding to later characters when needed

    4. D

      It treats every string comparison as a numeric comparison

    Correct answer
    C

    It compares characters in sequence, proceeding to later characters when needed

    Explanation

    For string comparisons, Python compares characters in order. When initial characters match, later characters are compared; alphabetically earlier letters are considered smaller.

  50. 50

    What is branching in a program?

    1. A

      It automatically changes a false condition into a true one

    2. B

      It forces every line in a program to run in reverse order

    3. C

      It selects program behavior according to a condition

    4. D

      It converts a condition into a reusable function

    Correct answer
    C

    It selects program behavior according to a condition

    Explanation

    A conditional statement allows a program to choose which code to execute based on whether a condition is true.

  51. 51

    When does the body of an if statement execute?

    1. A

      It runs only when the if condition evaluates to True

    2. B

      It runs repeatedly until the condition becomes false

    3. C

      It runs only after a matching else block has run

    4. D

      It runs once whether the condition is true or false

    Correct answer
    A

    It runs only when the if condition evaluates to True

    Explanation

    The indented body of an if block runs only when its condition evaluates to True. If the condition is False, that body is skipped.

  52. 52

    What is the purpose of an else statement?

    1. A

      It executes before the if condition is evaluated

    2. B

      It repeats the preceding if condition a second time

    3. C

      It executes when the preceding if condition is False

    4. D

      It executes whenever the if condition is True

    Correct answer
    C

    It executes when the preceding if condition is False

    Explanation

    An else block provides an alternative path that executes when the preceding if condition is False.

  53. 53

    When is elif useful?

    1. A

      It executes only when every preceding condition is True

    2. B

      It repeats the first condition until it becomes True

    3. C

      It tests a further condition when earlier conditions were False

    4. D

      It defines a function that returns several conditions

    Correct answer
    C

    It tests a further condition when earlier conditions were False

    Explanation

    An elif statement tests another condition when the preceding conditions were not true, avoiding many nested if-else blocks.

  54. 54

    What does the modulo operator return?

    1. A

      It converts the divisor to a Boolean value

    2. B

      It returns the remainder after division

    3. C

      It returns the result of multiplying two values

    4. D

      It returns the quotient after integer division

    Correct answer
    B

    It returns the remainder after division

    Explanation

    The modulo operator returns the remainder after division. An integer divided by 2 has remainder 0 when it is even.

  55. 55

    How can a function test whether an integer is even using modulo?

    1. A

      Check whether the number multiplied by 2 equals 0

    2. B

      Check whether the number divided by 2 is greater than 0

    3. C

      Check whether the number modulo 2 equals 0

    4. D

      Check whether the number is less than 2

    Correct answer
    C

    Check whether the number modulo 2 equals 0

    Explanation

    A number is even if dividing it by 2 leaves a remainder of 0, so a modulo check can test evenness.

  56. 56

    How does a while loop determine whether to continue?

    1. A

      It repeats its body while its condition evaluates to True

    2. B

      It executes its body only when the condition is False

    3. C

      It executes its body exactly once, regardless of its condition

    4. D

      It iterates through a fixed sequence of values only

    Correct answer
    A

    It repeats its body while its condition evaluates to True

    Explanation

    A while loop repeatedly executes its body while its condition is True. The condition must eventually change or the loop may continue indefinitely.

  57. 57

    In a while loop that starts with x = 0, runs while x < 5, and adds 1 each time, when does the loop stop?

    1. A

      It stops after x reaches 5 and the condition is false

    2. B

      It stops before printing the value of x

    3. C

      It stops when x first becomes 1

    4. D

      It continues indefinitely because x is initialized to 0

    Correct answer
    A

    It stops after x reaches 5 and the condition is false

    Explanation

    The while-loop example initializes x at 0, checks x < 5, and increments x by 1 on each iteration. The loop stops when x reaches 5.

  58. 58

    What is the defining behavior of a for loop?

    1. A

      It repeats only while a manually updated Boolean remains true

    2. B

      It runs only when a list contains no duplicate elements

    3. C

      It executes a body once for each variable in a function

    4. D

      It iterates over the values of a sequence or iterable

    Correct answer
    D

    It iterates over the values of a sequence or iterable

    Explanation

    A for loop iterates over the values in a sequence or other iterable, assigning each value in turn to its loop variable.

  59. 59

    Which statement correctly distinguishes an iteration from an iterable?

    1. A

      An iteration is one execution; an iterable is an object traversed by a loop

    2. B

      An iteration is a data type; an iterable is a variable assignment

    3. C

      An iteration is a collection; an iterable is one execution of a function

    4. D

      An iteration is a conditional; an iterable is a comment in a loop

    Correct answer
    A

    An iteration is one execution; an iterable is an object traversed by a loop

    Explanation

    An iteration is one execution of a block of code. A loop is the code that carries out iterations, and an iterable is an object whose values can be traversed.

  60. 60

    What sequence does range(5) generate by default?

    1. A

      It starts at the specified stop value and counts backward

    2. B

      It starts at 0 and includes the specified stop value

    3. C

      It starts at 1 and includes the specified stop value

    4. D

      It starts at 0 and stops before the specified stop value

    Correct answer
    D

    It starts at 0 and stops before the specified stop value

    Explanation

    The range function starts at 0 by default, advances by 1, and stops before its specified stop value. Thus, range(5) produces 0 through 4.

  61. 61

    How does range(1, 10) support a loop that calculates the factorial of 9?

    1. A

      It multiplies the integers 1 through 9, excluding 10

    2. B

      It multiplies every integer from 1 through 10

    3. C

      It multiplies every second integer from 1 through 10

    4. D

      It multiplies the integers 0 through 9, excluding 1

    Correct answer
    A

    It multiplies the integers 1 through 9, excluding 10

    Explanation

    The range function can take start, stop, and step values. Since the stop value is excluded, range(1, 10) covers integers 1 through 9.

  62. 62

    What does the third parameter of range specify?

    1. A

      It selects whether the sequence begins at zero or one

    2. B

      It specifies how many times the loop body must be printed

    3. C

      It changes the range stop value into an inclusive endpoint

    4. D

      It specifies the increment between successive values

    Correct answer
    D

    It specifies the increment between successive values

    Explanation

    The third range parameter specifies the step size. For a sequence from 0 to 100 in increments of 10, the stop must be 101 to include 100.

  63. 63

    Which guideline best distinguishes when to use for and while loops?

    1. A

      Use for loops for a sequence and while loops for a condition-controlled repetition

    2. B

      Use while loops for every list and for loops only for integers

    3. C

      Use for loops when no iterable exists and while loops for fixed-length data

    4. D

      Use while loops only when the loop body should execute once

    Correct answer
    A

    Use for loops for a sequence and while loops for a condition-controlled repetition

    Explanation

    A for loop is a natural choice when iterating over a known sequence or fixed collection. A while loop is useful when repetition should continue until a Boolean condition changes.

  64. 64

    Why must a guessing-game loop update its number-of-guesses counter?

    1. A

      The loop should increase its limit after every incorrect guess

    2. B

      The loop should leave its counter unchanged so the user can retry

    3. C

      The loop should update an attempt counter so it can reach its limit

    4. D

      The loop should compare the guess only with a string value

    Correct answer
    C

    The loop should update an attempt counter so it can reach its limit

    Explanation

    A loop that keeps a counter of incorrect or total guesses can limit the user to a fixed number of attempts. Updating the counter is necessary for the condition to eventually end the loop.

  65. 65

    Why should a number entered with input be converted before comparing it with a generated integer?

    1. A

      Input returns a string, so a numeric guess must be converted to an integer

    2. B

      Input returns a Boolean, so it must be converted to a float

    3. C

      Input returns an integer, so the generated number must become a string

    4. D

      Input returns a list, so it must be converted to a tuple

    Correct answer
    A

    Input returns a string, so a numeric guess must be converted to an integer

    Explanation

    The input function returns the user's entry as a string. Converting a numeric guess to an integer allows it to be compared with a randomly generated integer.

  66. 66

    What does the break keyword do inside a loop?

    1. A

      It runs the loop's else block before each new iteration

    2. B

      It skips only the current iteration and always repeats the loop

    3. C

      It exits the loop immediately

    4. D

      It resets the loop's counter to its initial value

    Correct answer
    C

    It exits the loop immediately

    Explanation

    The break keyword exits a loop immediately, allowing execution to continue after the loop without waiting for its condition to become false.

  67. 67

    Which operations can concatenate and repeat strings?

    1. A

      Use + to join strings and * to repeat a string

    2. B

      Use / to join strings and + to repeat a string

    3. C

      Use ** to join strings and - to repeat a string

    4. D

      Use - to join strings and / to repeat a string

    Correct answer
    A

    Use + to join strings and * to repeat a string

    Explanation

    Strings can be concatenated with + and repeated with *. The content must include whitespace if a space is desired between concatenated strings.

  68. 68

    What does a backslash do when used as an escape character in a string?

    1. A

      It makes a string mutable while a program runs

    2. B

      It assigns special meaning to every character in the string

    3. C

      It converts the string into a list of characters

    4. D

      It changes the usual interpretation of a following character

    Correct answer
    D

    It changes the usual interpretation of a following character

    Explanation

    A backslash can act as an escape character, changing the normal interpretation of characters that follow it, such as quotation marks in a string.

  69. 69

    What does \n normally represent in a Python string?

    1. A

      It represents the end of a string, and escaping it starts one

    2. B

      It represents a quotation mark, and escaping it deletes the mark

    3. C

      It represents a tab, and escaping it removes the tab

    4. D

      It represents a newline, and escaping it allows literal characters

    Correct answer
    D

    It represents a newline, and escaping it allows literal characters

    Explanation

    The sequence \n represents a newline. To display the characters backslash and n literally, the backslash itself must be escaped.

  70. 70

    What is indexing, and where is the first element located in Python?

    1. A

      Indexing changes an iterable into an unordered collection

    2. B

      Indexing accesses an element by position, beginning at 0

    3. C

      Indexing identifies only the data type of an element

    4. D

      Indexing finds every occurrence of a substring

    Correct answer
    B

    Indexing accesses an element by position, beginning at 0

    Explanation

    Indexing identifies an element by its position in an iterable. Python uses zero-based indexing, so the first element is at index 0.

  71. 71

    How do negative indices work in a string or other sequence?

    1. A

      Negative indices select only elements with negative values

    2. B

      Negative indices remove elements from the sequence

    3. C

      Negative indices count backward from the end of a sequence

    4. D

      Negative indices count forward from the beginning

    Correct answer
    C

    Negative indices count backward from the end of a sequence

    Explanation

    Negative indexing counts from the end of a sequence. Index -1 refers to the last element, and -2 to the second-to-last.

  72. 72

    Which positions are selected by the slice [1:4]?

    1. A

      It includes indices 0 through 4

    2. B

      It includes indices 1 through 3, excluding the endpoint

    3. C

      It includes indices 1 through 4, including both endpoints

    4. D

      It includes only index 4

    Correct answer
    B

    It includes indices 1 through 3, excluding the endpoint

    Explanation

    A slice such as [1:4] includes indices 1, 2, and 3 but excludes the ending index 4.

  73. 73

    What do omitted start and end indices mean in a slice?

    1. A

      An omitted start defaults to 0; an omitted end defaults to the sequence's end

    2. B

      Omitting either index makes the slice empty

    3. C

      An omitted start defaults to the sequence's end; an omitted end defaults to 0

    4. D

      An omitted start means the slice begins at index 1; an omitted end means it stops at index 0

    Correct answer
    A

    An omitted start defaults to 0; an omitted end defaults to the sequence's end

    Explanation

    If the starting index is omitted, a slice begins at 0. If the ending index is omitted, it continues through the end of the sequence.

  74. 74

    How can Python check whether one string is contained in another?

    1. A

      It returns the position of the last matching substring

    2. B

      It checks for membership and produces a Boolean result

    3. C

      It changes the sequence to contain the searched value

    4. D

      It removes the searched substring from the sequence

    Correct answer
    B

    It checks for membership and produces a Boolean result

    Explanation

    The in keyword tests whether a substring or element occurs in a sequence and produces a Boolean result.

  75. 75

    What behavior does the string index method have?

    1. A

      It returns the last match's position and inserts missing text

    2. B

      It returns the number of matches and deletes the first one

    3. C

      It returns the first match's position and errors if no match exists

    4. D

      It returns every matching position and returns zero if none exist

    Correct answer
    C

    It returns the first match's position and errors if no match exists

    Explanation

    The str.index method returns the position of the first matching character or substring. It raises a ValueError if no match exists.

  76. 76

    What does the string format method do?

    1. A

      It converts a string into an iterable without placeholders

    2. B

      It changes the order of arguments automatically based on their types

    3. C

      It joins only strings that have the same data type

    4. D

      It inserts supplied values into designated placeholders

    Correct answer
    D

    It inserts supplied values into designated placeholders

    Explanation

    The format method inserts supplied values into designated braces. Arguments can be placed by position, by explicit keyword, or by numeric position.

  77. 77

    What does the format specification .2f indicate?

    1. A

      It converts the float into a two-character string

    2. B

      It aligns the value two spaces to the left

    3. C

      It rounds the value to two significant digits and removes decimals

    4. D

      It displays a float with two digits after the decimal point

    Correct answer
    D

    It displays a float with two digits after the decimal point

    Explanation

    In formatted output, a specification such as .2f displays a floating-point value with two digits after the decimal point.

  78. 78

    Which description best fits a Python list?

    1. A

      They are immutable sequences containing only characters

    2. B

      They are ordered, mutable collections that can contain duplicates

    3. C

      They are unordered and immutable collections of unique values

    4. D

      They are key-value collections accessed only by keys

    Correct answer
    B

    They are ordered, mutable collections that can contain duplicates

    Explanation

    Lists are ordered, mutable collections. They can contain repeated elements and support indexing and slicing.

  79. 79

    How is a list typically written in Python?

    1. A

      Quotation marks enclose the list, and periods separate its elements

    2. B

      Braces enclose the list, and equal signs separate its elements

    3. C

      Parentheses enclose the list, and colons separate its elements

    4. D

      Square brackets enclose the list, and commas separate its elements

    Correct answer
    D

    Square brackets enclose the list, and commas separate its elements

    Explanation

    Lists use square brackets, with commas separating their elements. Their elements can have different data types.

  80. 80

    Which comparison between lists and strings is correct?

    1. A

      Both are mutable, but only strings support indexing

    2. B

      Both are ordered sequences, but only lists are mutable

    3. C

      Lists are unordered, while strings are ordered

    4. D

      Both are immutable, but only lists support slicing

    Correct answer
    B

    Both are ordered sequences, but only lists are mutable

    Explanation

    Lists and strings are both ordered sequences that support indexing and slicing and can contain duplicate elements. Lists are mutable, while strings are immutable.

  81. 81

    What does the list append method do?

    1. A

      It adds an element to the end of a list

    2. B

      It replaces the element at a specified index

    3. C

      It inserts an element at the beginning of a list

    4. D

      It removes the first matching element

    Correct answer
    A

    It adds an element to the end of a list

    Explanation

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

  82. 82

    How does the list insert method work?

    1. A

      It takes an index and an element to insert at that position

    2. B

      It takes an element and removes the matching list item

    3. C

      It takes a list and adds it as several separate elements

    4. D

      It takes an index and returns the element without removing it

    Correct answer
    A

    It takes an index and an element to insert at that position

    Explanation

    The insert method takes an index and an element, then inserts that element at the specified position in the list.

  83. 83

    What does the list remove method do?

    1. A

      It removes the element at a given index and returns it

    2. B

      It removes a matching value and raises an error if that value is absent

    3. C

      It removes the final element whether or not a value is specified

    4. D

      It removes all duplicate values and returns a new list

    Correct answer
    B

    It removes a matching value and raises an error if that value is absent

    Explanation

    The remove method deletes the first matching element by value. If the requested value is not present, it raises a ValueError.

  84. 84

    What is the behavior of the list pop method?

    1. A

      It replaces a value at an index with a new value

    2. B

      It adds an element at the end of a list

    3. C

      It removes and returns the element at a specified index

    4. D

      It removes the first occurrence of a specified value

    Correct answer
    C

    It removes and returns the element at a specified index

    Explanation

    The pop method removes an element by index. The removed element is extracted from the list.

  85. 85

    How does mutability affect changing a list element versus a string character?

    1. A

      A string can be changed in place, but a list cannot

    2. B

      A list can be changed in place, but a string cannot

    3. C

      Both can be changed in place only if they contain numbers

    4. D

      Neither lists nor strings can be changed at a particular index

    Correct answer
    B

    A list can be changed in place, but a string cannot

    Explanation

    Lists are mutable, so an element can be changed directly at an index. Strings are immutable, so changing one character in place produces an error; a new string must be assigned instead.

  86. 86

    What is a tuple?

    1. A

      An immutable sequence that can contain different data types

    2. B

      A mutable, unordered collection of unique elements

    3. C

      A key-value collection whose values must be strings

    4. D

      A numerical array whose elements must share one data type

    Correct answer
    A

    An immutable sequence that can contain different data types

    Explanation

    A tuple is an immutable sequence that can contain elements of different data types and is commonly written with parentheses.

  87. 87

    What does it mean to unpack a tuple?

    1. A

      Converting each element of a tuple into a dictionary key

    2. B

      Sorting a tuple into a list of key-value pairs

    3. C

      Assigning a tuple's elements to separate variables

    4. D

      Changing the tuple's elements without creating a new tuple

    Correct answer
    C

    Assigning a tuple's elements to separate variables

    Explanation

    Tuple unpacking assigns the elements of a tuple to separate variables, allowing those variables to be used individually.

  88. 88

    How does Python represent multiple values returned by a function?

    1. A

      It returns a tuple containing the values

    2. B

      It returns several independent values without a container

    3. C

      It returns a list that cannot be unpacked

    4. D

      It returns a dictionary whose keys are the values

    Correct answer
    A

    It returns a tuple containing the values

    Explanation

    When a function returns more than one value, Python packages those values as a tuple, which can then be unpacked.

  89. 89

    Why might player records be stored as tuples inside a list?

    1. A

      Use a string for the collection and a tuple for each column

    2. B

      Use a mutable list for the collection and an immutable tuple for each record

    3. C

      Use a set for the collection and a dictionary for each record

    4. D

      Use a tuple for the collection and a list for each immutable record

    Correct answer
    B

    Use a mutable list for the collection and an immutable tuple for each record

    Explanation

    A list can hold a collection of records, while each record can be a tuple to indicate that the record's values are not intended to change.

  90. 90

    How does a dictionary provide access to its data?

    1. A

      It stores an ordered sequence that is accessed by integer index

    2. B

      It stores only values, while keys are generated during iteration

    3. C

      It maps positions to values and supports lookup in either direction

    4. D

      It maps keys to values, and lookup by key retrieves the associated value

    Correct answer
    D

    It maps keys to values, and lookup by key retrieves the associated value

    Explanation

    A dictionary maps keys to values. Looking up a key provides its associated value; looking up a value does not automatically find its key.

  91. 91

    Which describes two ways to create a dictionary?

    1. A

      With braces and key=value pairs, or with dict and list indices

    2. B

      Only with square brackets containing comma-separated values

    3. C

      Only with parentheses containing positional indices

    4. D

      With braces and key:value pairs, or with dict and suitable keyword arguments

    Correct answer
    D

    With braces and key:value pairs, or with dict and suitable keyword arguments

    Explanation

    A dictionary can be created with braces using colons between keys and values, or with dict and keyword arguments when keys are strings.

  92. 92

    Which constraint applies to dictionary keys?

    1. A

      Keys must be lists so they can be changed after insertion

    2. B

      Keys must be mutable, so lists are valid but strings are not

    3. C

      Keys must be unique strings and cannot be numbers or tuples

    4. D

      Keys must be immutable, so a list cannot be used as a key

    Correct answer
    D

    Keys must be immutable, so a list cannot be used as a key

    Explanation

    Dictionary keys must be immutable, so strings, numbers, and tuples can be keys, while mutable lists cannot.

  93. 93

    What should you use if the position order of a collection matters?

    1. A

      Dictionaries are indexed by position, so they are preferred for ordered records

    2. B

      Dictionaries are always sorted by their values

    3. C

      Dictionaries preserve positions only when all keys are integers

    4. D

      Dictionaries are accessed by keys, so lists suit order-dependent data better

    Correct answer
    D

    Dictionaries are accessed by keys, so lists suit order-dependent data better

    Explanation

    Dictionaries are unordered in the described model and are accessed by keys, not by positional index. A list is a better choice when position order matters.

  94. 94

    What does key in dictionary test?

    1. A

      It checks whether a value appears anywhere in the dictionary

    2. B

      It checks whether a key exists in the dictionary

    3. C

      It checks whether a key's value is truthy

    4. D

      It checks whether a dictionary is in a particular position

    Correct answer
    B

    It checks whether a key exists in the dictionary

    Explanation

    Using in with a dictionary checks whether a key exists. It does not test whether a value occurs in the dictionary.

  95. 95

    What do the dictionary methods keys, values, and items provide?

    1. A

      keys returns keys, values returns values, and items returns pairs

    2. B

      keys returns values, values returns pairs, and items returns keys

    3. C

      keys returns pairs, values returns keys, and items returns values

    4. D

      All three methods return only dictionary keys

    Correct answer
    A

    keys returns keys, values returns values, and items returns pairs

    Explanation

    The keys, values, and items methods retrieve, respectively, dictionary keys, dictionary values, and key-value pairs.

  96. 96

    What does a basic for loop over a dictionary iterate over by default?

    1. A

      It yields the values only

    2. B

      It yields key-value pairs only

    3. C

      It yields the keys by default

    4. D

      It yields values in sorted order

    Correct answer
    C

    It yields the keys by default

    Explanation

    When looping directly over a dictionary, iteration yields its keys by default. The values or pairs can be accessed through the corresponding methods.

  97. 97

    Which description best fits a Python set?

    1. A

      It contains unique, unordered elements and is itself mutable

    2. B

      It contains only numerical values and is immutable

    3. C

      It contains ordered, repeated values and cannot be modified

    4. D

      It contains key-value pairs that are accessed by index

    Correct answer
    A

    It contains unique, unordered elements and is itself mutable

    Explanation

    A set contains unique, unordered elements. Its elements must be immutable, although the set itself can be modified.

  98. 98

    What happens when a list with duplicate elements is passed to set?

    1. A

      It turns every iterable into a dictionary of positions

    2. B

      It sorts the iterable and converts each element to a string

    3. C

      It keeps only unique elements from the iterable

    4. D

      It preserves every duplicate and keeps the iterable's order

    Correct answer
    C

    It keeps only unique elements from the iterable

    Explanation

    Passing an iterable to set creates a set of its distinct elements. Repeated values are removed; a string is treated as an iterable of characters.

  99. 99

    How should an empty set be created?

    1. A

      Use (), because empty parentheses create an empty set

    2. B

      Use set(), because empty braces create a dictionary

    3. C

      Use {}, because empty braces always create a set

    4. D

      Use [], because square brackets create an empty set

    Correct answer
    B

    Use set(), because empty braces create a dictionary

    Explanation

    Empty braces create an empty dictionary, not a set. Use set() to create an empty set.

  100. 100

    Why can a set not be accessed with ordinary positional indexing?

    1. A

      They can be indexed only by negative positions

    2. B

      They can be indexed but cannot be sliced

    3. C

      They cannot be indexed or sliced by position

    4. D

      They can be sliced only if their values are strings

    Correct answer
    C

    They cannot be indexed or sliced by position

    Explanation

    Sets do not support positional indexing or slicing because their elements are unordered.

  101. 101

    Which description correctly compares common set operations?

    1. A

      Intersection returns one-sided elements; union returns shared elements; difference returns all; symmetric difference returns duplicates

    2. B

      Intersection returns all elements; union returns shared elements; difference returns paired elements

    3. C

      Intersection returns shared elements; union returns all; difference returns one-sided elements; symmetric difference returns elements not shared

    4. D

      Intersection removes duplicates; union sorts values; difference reverses the sets; symmetric difference returns their common elements

    Correct answer
    C

    Intersection returns shared elements; union returns all; difference returns one-sided elements; symmetric difference returns elements not shared

    Explanation

    Intersection returns elements common to both sets; union returns all elements in either set; difference returns elements in one set but not the other; symmetric difference returns elements in exactly one set.

  102. 102

    How does set difference differ from symmetric difference?

    1. A

      Difference is directional, while symmetric difference returns nonshared elements from both sets

    2. B

      Difference returns shared elements, while symmetric difference returns only elements from the first set

    3. C

      Both operations return all elements from both sets

    4. D

      Difference is symmetric, while symmetric difference depends on operand order

    Correct answer
    A

    Difference is directional, while symmetric difference returns nonshared elements from both sets

    Explanation

    Difference is directional: A - B contains elements in A that are not in B. Symmetric difference returns elements found in either set but not both.

  103. 103

    What is a list comprehension?

    1. A

      It changes an existing list into a tuple without copying values

    2. B

      It creates a dictionary by placing keys after the for clause

    3. C

      It sorts an existing list by applying a comparison function

    4. D

      It builds a new list by expressing the element calculation before the for clause

    Correct answer
    D

    It builds a new list by expressing the element calculation before the for clause

    Explanation

    A list comprehension creates a new list from an existing iterable by placing the desired expression before the for clause.

  104. 104

    What is a nested loop?

    1. A

      A loop placed inside another loop

    2. B

      A loop that contains two conditions but no body

    3. C

      Two loops that run once in alternating order

    4. D

      A loop that calls itself until a list is empty

    Correct answer
    A

    A loop placed inside another loop

    Explanation

    A nested loop is a loop inside another loop. For each outer-loop iteration, the inner loop runs through its sequence.

  105. 105

    What is a Python library or package?

    1. A

      A data structure used exclusively for unordered values

    2. B

      A reusable collection of code that may contain modules

    3. C

      A file format that separates values with commas

    4. D

      A single variable accessible only inside a function

    Correct answer
    B

    A reusable collection of code that may contain modules

    Explanation

    A library or package is a reusable collection of code that may contain modules and documentation. The terms are often used interchangeably.

  106. 106

    What is a Python module?

    1. A

      A variable that can only be accessed within one function

    2. B

      A single notebook cell that cannot be reused

    3. C

      A Python file containing reusable code components

    4. D

      A table with labeled rows and columns

    Correct answer
    C

    A Python file containing reusable code components

    Explanation

    A module is a Python file containing collections of functions, classes, or global variables that can be imported into a program.

  107. 107

    What distinguishes a global variable?

    1. A

      They are values that cannot be reassigned

    2. B

      They can be accessed only inside the function that creates them

    3. C

      They are variables that exist only in imported libraries

    4. D

      They can be accessed from anywhere in a program or script

    Correct answer
    D

    They can be accessed from anywhere in a program or script

    Explanation

    Global variables can be accessed from anywhere in a program or script, unlike variables limited to a local scope.

  108. 108

    Which comparison of common Python data libraries is accurate?

    1. A

      Matplotlib creates visualizations; Seaborn simplifies common plots; NumPy supports numerical computation; pandas analyzes tabular data

    2. B

      Matplotlib tests models; Seaborn manages files; NumPy formats tables; pandas controls program flow

    3. C

      Matplotlib stores arrays; Seaborn reads databases; NumPy creates reports; pandas generates random values

    4. D

      Matplotlib analyzes tables; Seaborn performs random sampling; NumPy formats strings; pandas creates modules

    Correct answer
    A

    Matplotlib creates visualizations; Seaborn simplifies common plots; NumPy supports numerical computation; pandas analyzes tabular data

    Explanation

    Matplotlib creates visualizations; Seaborn is based on Matplotlib and provides a simpler interface for common plots. NumPy supports numerical computation, while pandas focuses on tabular data manipulation and analysis.

  109. 109

    What does vectorization mean in NumPy?

    1. A

      It converts all data into strings before calculation

    2. B

      It performs an operation on multiple data components together

    3. C

      It applies an operation to one element per separate loop iteration

    4. D

      It stores each element in a separate Python module

    Correct answer
    B

    It performs an operation on multiple data components together

    Explanation

    Vectorization applies operations to multiple components at once. This can make code simpler and faster and can reduce memory use compared with element-by-element iteration.

  110. 110

    What is a NumPy ndarray?

    1. A

      A dictionary whose keys are numeric indices

    2. B

      A two-dimensional table that can contain arbitrary mixed types

    3. C

      A module that contains only plotting functions

    4. D

      An N-dimensional array used for vectorized operations

    Correct answer
    D

    An N-dimensional array used for vectorized operations

    Explanation

    The NumPy ndarray is its core data structure. It is an N-dimensional array that supports vectorized computation.

  111. 111

    Which statement about modifying a NumPy array is correct?

    1. A

      Both values and size can always be changed in place

    2. B

      Element values can change, but changing the array's size requires reassignment

    3. C

      Array size can change in place, but element values cannot

    4. D

      Neither element values nor array size can ever change

    Correct answer
    B

    Element values can change, but changing the array's size requires reassignment

    Explanation

    NumPy arrays are mutable, so their elements can be changed. Their size cannot be changed in place; changing the size requires creating and assigning a replacement array.

  112. 112

    What happens when a NumPy array is created from values of mixed types?

    1. A

      Arrays can contain only integers and floats together

    2. B

      All elements share one data type, with conversion when possible

    3. C

      Each element must have a different data type

    4. D

      Mixed types always cause an error when the array is created

    Correct answer
    B

    All elements share one data type, with conversion when possible

    Explanation

    An ndarray must have one element data type. NumPy may coerce mixed input values to a common type, such as converting integers to strings when possible.

  113. 113

    What information do shape, ndim, and dtype provide for a NumPy array?

    1. A

      shape gives the element type, ndim gives the shape, and dtype gives the dimension count

    2. B

      shape gives the dimensions, ndim gives the dimension count, and dtype gives the element type

    3. C

      shape gives the dimension count, ndim gives the element type, and dtype gives the shape

    4. D

      All three attributes report the number of array elements

    Correct answer
    B

    shape gives the dimensions, ndim gives the dimension count, and dtype gives the element type

    Explanation

    The shape attribute gives an array's dimensions, while ndim reports the number of dimensions. The dtype attribute identifies the element data type.

  114. 114

    How can a two-dimensional NumPy array be created from Python data?

    1. A

      It is created from a tuple of keys and values and has two dimensions

    2. B

      It is created from a list of unequal-length strings and has one dimension

    3. C

      It can be created from equally sized lists, with rows and columns

    4. D

      It must contain two arrays of different data types

    Correct answer
    C

    It can be created from equally sized lists, with rows and columns

    Explanation

    A two-dimensional array can be constructed from a list of equally sized lists. Its shape corresponds to its number of rows and columns.

  115. 115

    What does the NumPy reshape method do?

    1. A

      It changes every value to a different data type

    2. B

      It converts the array's elements into dictionary keys

    3. C

      It reorganizes an array into a specified compatible shape

    4. D

      It appends a new element to the array

    Correct answer
    C

    It reorganizes an array into a specified compatible shape

    Explanation

    The reshape method changes the organization and dimensions of an array. The requested shape must be compatible with the number of elements.

  116. 116

    Why is NumPy commonly imported with the alias np?

    1. A

      It prevents NumPy's array functions from being used

    2. B

      It provides a shorter name for referring to NumPy

    3. C

      It converts NumPy into a built-in Python function

    4. D

      It creates a second copy of the NumPy library

    Correct answer
    B

    It provides a shorter name for referring to NumPy

    Explanation

    The alias np is the conventional short name for NumPy. Aliasing makes references shorter, while following the standard makes code familiar to other readers.

  117. 117

    Why is understanding NumPy useful when learning pandas?

    1. A

      Pandas is a replacement for Python's built-in syntax

    2. B

      Pandas is built on NumPy, so NumPy knowledge supports pandas work

    3. C

      Pandas requires every operation to be written as a Python loop

    4. D

      Pandas is a plotting library that cannot use numerical arrays

    Correct answer
    B

    Pandas is built on NumPy, so NumPy knowledge supports pandas work

    Explanation

    Pandas is built on NumPy and uses NumPy arrays and functionality. Understanding NumPy concepts helps when working with pandas.

  118. 118

    What is a pandas DataFrame?

    1. A

      A one-dimensional sequence of unlabeled values

    2. B

      A function that reads only comma-separated text

    3. C

      An unordered collection of unique elements

    4. D

      A two-dimensional labeled structure with rows and columns

    Correct answer
    D

    A two-dimensional labeled structure with rows and columns

    Explanation

    A pandas DataFrame is a two-dimensional labeled data structure with rows and columns, similar to a spreadsheet or SQL table.

  119. 119

    What is a pandas Series?

    1. A

      A two-dimensional unlabeled matrix containing only numbers

    2. B

      A one-dimensional labeled array, often representing a row or column

    3. C

      A module that imports CSV files into Python

    4. D

      A collection of dictionary keys with no associated values

    Correct answer
    B

    A one-dimensional labeled array, often representing a row or column

    Explanation

    A pandas Series is a one-dimensional labeled array and commonly represents one row or column from a DataFrame.

  120. 120

    Which pandas tools can create DataFrames from Python objects and CSV files?

    1. A

      Use read_csv for dictionaries and DataFrame only for text files

    2. B

      Use DataFrame for Python objects and read_csv for CSV files

    3. C

      Use type for CSV files and shape for dictionaries

    4. D

      Use Series for every table and read_csv for NumPy arrays

    Correct answer
    B

    Use DataFrame for Python objects and read_csv for CSV files

    Explanation

    Pandas provides a DataFrame function for creating DataFrames from sources such as dictionaries and NumPy arrays, as well as a read_csv function for CSV files.

  121. 121

    What does CSV stand for, and how are values separated in it?

    1. A

      A pandas object that stores row and column labels

    2. B

      A plaintext format that uses commas to separate values

    3. C

      A module that converts strings into Python functions

    4. D

      A file format that stores values only in binary form

    Correct answer
    B

    A plaintext format that uses commas to separate values

    Explanation

    CSV means comma-separated values. It is a plaintext format in which commas separate distinct values.

  122. 122

    Which statement correctly describes common DataFrame attributes and methods?

    1. A

      columns reports memory use, shape reports non-null counts, and info returns row labels

    2. B

      columns gives column labels, shape gives dimensions, and info summarizes structure

    3. C

      columns reports row counts, shape reports data types, and info returns only column names

    4. D

      All three return the actual values from every cell in the DataFrame

    Correct answer
    B

    columns gives column labels, shape gives dimensions, and info summarizes structure

    Explanation

    The columns attribute provides column labels, shape provides the number of rows and columns, and info summarizes columns, types, non-null counts, and memory use.

  123. 123

    How are null values commonly represented in pandas?

    1. A

      Missing values are represented as the string 'null' in every case

    2. B

      Missing values are always represented as zero

    3. C

      Missing values are represented as NaN

    4. D

      Missing values are represented as an empty dictionary

    Correct answer
    C

    Missing values are represented as NaN

    Explanation

    Pandas represents missing or null values as NaN, short for 'not a number.'

  124. 124

    What is returned when selecting one column versus multiple columns by name?

    1. A

      Selecting one column returns a DataFrame, while several columns return a Series

    2. B

      Both single- and multiple-column selection return a NumPy array

    3. C

      Selecting one column returns a dictionary, while several return a tuple

    4. D

      Selecting one column returns a Series, while several return a DataFrame

    Correct answer
    D

    Selecting one column returns a Series, while several return a DataFrame

    Explanation

    Selecting one DataFrame column by name returns a Series. Selecting multiple columns using a list of names returns a DataFrame.

  125. 125

    Which statement about selecting DataFrame columns by name is accurate?

    1. A

      Dot notation and bracket notation always return different data types

    2. B

      Bracket notation is general, while dot notation has restrictions on column names

    3. C

      Dot notation works for every column name, including names with spaces

    4. D

      Bracket notation selects rows only, while dot notation selects columns only

    Correct answer
    B

    Bracket notation is general, while dot notation has restrictions on column names

    Explanation

    Bracket notation can select columns by name. Dot notation can also work for simple column names without whitespace, but brackets are more general and often clearer.

  126. 126

    How does iloc select rows and columns?

    1. A

      It selects rows and columns only by their labels

    2. B

      It selects columns by name and rows by Boolean value

    3. C

      It selects values by their data types

    4. D

      It selects by integer position, with a range excluding its endpoint

    Correct answer
    D

    It selects by integer position, with a range excluding its endpoint

    Explanation

    iloc selects by integer position. A single integer selects a row, and ranges use a start-inclusive, end-exclusive convention.

  127. 127

    What is the primary difference between loc and iloc?

    1. A

      Both select only by column names

    2. B

      loc selects by integer positions, while iloc selects by labels

    3. C

      loc selects by labels, while iloc selects by integer positions

    4. D

      Both select only by Boolean masks

    Correct answer
    C

    loc selects by labels, while iloc selects by integer positions

    Explanation

    loc selects using labels, such as named row indices and column names, whereas iloc selects by integer position.

  128. 128

    How does Boolean masking filter a DataFrame?

    1. A

      It overlays column names and keeps only matching labels

    2. B

      It filters rows according to aligned True and False values

    3. C

      It sorts all rows according to their Boolean values

    4. D

      It changes every False value in the DataFrame to NaN

    Correct answer
    B

    It filters rows according to aligned True and False values

    Explanation

    A Boolean mask is a Boolean Series aligned with the DataFrame's index. Applying it keeps rows marked True and filters out rows marked False.

  129. 129

    Which symbols represent and, or, and not in pandas Boolean filtering?

    1. A

      Use | for and, & for or, and ~ for equality

    2. B

      Use + for and, - for or, and / for not

    3. C

      Use & for and, | for or, and ~ for not

    4. D

      Use ~ for and, & for not, and | for equality

    Correct answer
    C

    Use & for and, | for or, and ~ for not

    Explanation

    In pandas Boolean conditions, & represents and, | represents or, and ~ represents not. Parentheses around each condition help ensure the logic is evaluated as intended.

  130. 130

    What does the pandas groupby method do?

    1. A

      It changes every column into a separate Series

    2. B

      It joins two DataFrames using matching column names

    3. C

      It groups rows by column values for subsequent analysis

    4. D

      It filters rows by a single Boolean condition

    Correct answer
    C

    It groups rows by column values for subsequent analysis

    Explanation

    The groupby method creates groups based on values in one or more columns. Applying an aggregation such as mean or sum then summarizes each group.

  131. 131

    What is the purpose of the pandas agg method?

    1. A

      It applies one or more calculations to grouped data

    2. B

      It concatenates rows without grouping them

    3. C

      It converts every group into a dictionary key

    4. D

      It creates a Boolean mask from a DataFrame

    Correct answer
    A

    It applies one or more calculations to grouped data

    Explanation

    The agg method applies one or more aggregation functions to grouped data, such as mean, median, or a custom-defined function.

  132. 132

    What do axes 0 and 1 indicate when concatenating DataFrames?

    1. A

      Axis 0 sorts rows; axis 1 sorts columns

    2. B

      Axis 0 selects keys; axis 1 selects values

    3. C

      Axis 0 is vertical across rows; axis 1 is horizontal across columns

    4. D

      Axis 0 is horizontal across columns; axis 1 is vertical across rows

    Correct answer
    C

    Axis 0 is vertical across rows; axis 1 is horizontal across columns

    Explanation

    The concat function can combine DataFrames vertically or horizontally. Axis 0 is vertical across rows; axis 1 is horizontal across columns.

  133. 133

    What is the role of reset_index(drop=True) after vertically concatenating DataFrames?

    1. A

      Vertical concatenation adds rows, and drop=True prevents keeping the old index as a column

    2. B

      Vertical concatenation adds columns, and reset_index deletes all data

    3. C

      Vertical concatenation adds keys, and reset_index sorts the values

    4. D

      Vertical concatenation adds rows, but reset_index always removes all columns

    Correct answer
    A

    Vertical concatenation adds rows, and drop=True prevents keeping the old index as a column

    Explanation

    Concatenating compatible DataFrames vertically adds rows. Resetting the index can create a fresh sequential index; drop=True prevents the old index from becoming a column.

  134. 134

    What is a key in the context of merging DataFrames?

    1. A

      It adds rows by matching their integer positions only

    2. B

      It combines only DataFrames that have identical row counts

    3. C

      It joins DataFrames based on shared points of reference called keys

    4. D

      It appends columns without considering common values

    Correct answer
    C

    It joins DataFrames based on shared points of reference called keys

    Explanation

    A merge joins DataFrames using shared keys, which provide common points of reference for matching rows.

  135. 135

    How do inner and outer joins differ?

    1. A

      Inner keeps keys from the left; outer keeps keys from the right

    2. B

      Inner keeps keys from the right; outer keeps keys from the left

    3. C

      Inner keeps all keys; outer keeps only shared keys

    4. D

      Inner keeps shared keys; outer keeps keys from both DataFrames

    Correct answer
    D

    Inner keeps shared keys; outer keeps keys from both DataFrames

    Explanation

    An inner join keeps matching keys found in both DataFrames. An outer join keeps all keys from both, with missing values where a row has no matching data.

  136. 136

    Which statement correctly describes left and right joins?

    1. A

      A left join retains all right keys; a right join retains all left keys

    2. B

      A left join retains all keys from both; a right join retains shared keys

    3. C

      Both joins retain only keys shared by the DataFrames

    4. D

      A left join retains all left keys; a right join retains all right keys

    Correct answer
    D

    A left join retains all left keys; a right join retains all right keys

    Explanation

    A left join retains every key from the left DataFrame; a right join retains every key from the right DataFrame.

  137. 137

    What happens to unmatched data during an outer join?

    1. A

      The unmatched columns are represented with NaN values

    2. B

      The unmatched key is removed from the outer join

    3. C

      The merge fails unless every key is present in both inputs

    4. D

      The missing values are replaced with zeros automatically

    Correct answer
    A

    The unmatched columns are represented with NaN values

    Explanation

    When an outer join includes a key that has no matching row in one DataFrame, the missing values from that DataFrame appear as NaN in the result.

  138. 138

    Which structure defines a tidy dataset?

    1. A

      Each file is a row, each business case is a column, and each variable is a table

    2. B

      Each observation is a column, each variable is a row, and each dataset is a cell

    3. C

      Each variable is a column, each observation is a row, and each observational unit is a table

    4. D

      Each variable is a separate table, each row is a data type, and columns are observations

    Correct answer
    C

    Each variable is a column, each observation is a row, and each observational unit is a table

    Explanation

    Tidy data is structured so each variable is a column, each observation is a row, and each type of observational unit is a table.

  139. 139

    What is the purpose of data tidying?

    1. A

      It structures data to facilitate analysis and related tasks

    2. B

      It converts every value to a string so formats are consistent

    3. C

      It removes all rows that contain more than one variable

    4. D

      It merges unrelated datasets into one table without keys

    Correct answer
    A

    It structures data to facilitate analysis and related tasks

    Explanation

    Tidying structures a dataset so that it is easier to manipulate, model, and visualize.

  140. 140

    What is the central data task in the portfolio project?

    1. A

      To build a machine learning model without examining the data

    2. B

      To create visualizations before the data is loaded

    3. C

      To load, clean, and structure data for a selected business scenario

    4. D

      To convert the dataset into a Python library

    Correct answer
    C

    To load, clean, and structure data for a selected business scenario

    Explanation

    The project task is to load, clean, and structure data from unstructured files so the result is a tidy dataset suited to a business scenario.

  141. 141

    Why document project steps and decisions in a strategy document?

    1. A

      It replaces the need to prepare a structured dataset

    2. B

      It records the process and reasoning for later explanation

    3. C

      It automatically determines which business scenario is correct

    4. D

      It converts unstructured files into Python functions

    Correct answer
    B

    It records the process and reasoning for later explanation

    Explanation

    Documenting the steps and reasoning in a PACE strategy document can help explain the work and thought process to future hiring managers.

  142. 142

    How should a data professional adapt an explanation of a project for an audience?

    1. A

      Focus only on tools and omit the business challenge

    2. B

      Consider the audience's goals, knowledge, and information needs

    3. C

      Assume every interviewer has the same technical background

    4. D

      Use the same technical detail regardless of the audience

    Correct answer
    B

    Consider the audience's goals, knowledge, and information needs

    Explanation

    When explaining a technical project, consider the audience's goals, existing knowledge, and information needs so the explanation is relevant to them.

Question 1 of 142
Question 1 of 142

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent