Free Practice Quiz Question List

2 Variables, Types, and Expressions Online Quiz Questions

Use this free practice quiz with 20 questions to review 2 Variables, Types, and Expressions, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

Which statement best describes a Python variable?

  1. A

    A variable is a value that can never change.

  2. B

    A variable is a name whose associated value can change.

  3. C

    A variable is always a string.

  4. D

    A variable is a Python keyword.

02
True or false
1 point

True or false: In Python, a variable name has a permanently declared type that cannot change during program execution.

  1. A

    True

  2. B

    False

03
Fill in the blank
1 point

To convert the string "42" into the integer 42, use the function.

04
Choose one
1 point

What happens when Python executes area = width * height?

  1. A

    The expression on the right is evaluated, then its result is bound to the name on the left.

  2. B

    The name on the left is compared with the expression on the right.

  3. C

    The expression on the left is evaluated, then its result is bound to the name on the right.

  4. D

    Both sides must already contain equal values.

05
True or false
1 point

True or false: After numbers = [1, 2, 3] and copy_of_numbers = numbers[:], appending 4 to copy_of_numbers also appends 4 to numbers.

  1. A

    True

  2. B

    False

06
Written response
1 point

What integer does int(3.9) produce?

07
Choose one
1 point

Given whole = 7 // 3 and remainder = 7 % 3, which result is correct?

  1. A

    whole is 2 and remainder is 1.

  2. B

    whole is 2.3333333333333335 and remainder is 0.

  3. C

    whole is 3 and remainder is 1.

  4. D

    Both variables are 1.

08
Fill in the blank
1 point

A list is , while a string is .

09
Choose all
1 point

Select all the Python types below that are commonly mutable.

  1. A

    list

  2. B

    int

  3. C

    dict

  4. D

    str

  5. E

    tuple

  6. F

    set

10
Choose all
1 point

A program reads quantity as a whole-number item count and unit_price as a price that may include cents. Which choices correctly prepare these values for total = quantity * unit_price? Select all that apply.

  1. A

    Use str() for both inputs.

  2. B

    Use int() for quantity.

  3. C

    Use float() for unit_price.

  4. D

    Use bool() for unit_price.

11
Open ended
1 point

Consider this code:

numbers = [1, 2, 3]

other_numbers = numbers

other_numbers.append(4)

Explain why printing numbers produces the changed list, and describe one way to create an independent shallow copy instead.

12
Choose one
1 point

What text is printed by this code?

name = "Ada"

year = 1843

print(f"{name} was born in {year}.")

  1. A

    {name} was born in {year}.

  2. B

    Ada was born in 1843.

  3. C

    name was born in year.

  4. D

    Ada was born in {1843}.

13
Choose one
1 point

Which statement best describes how Python evaluates total = price * quantity?

  1. A

    The name on the left is compared with the expression on the right.

  2. B

    The expression on the right is evaluated before its result is bound to the name on the left.

  3. C

    The name on the left is converted to the type of the expression on the right before evaluation.

  4. D

    Both sides are evaluated as Boolean conditions.

14
Choose one
1 point

What value does whole = int(3.9) assign to whole?

  1. A

    3

  2. B

    4

  3. C

    3.9

  4. D

    A ValueError is raised.

15
True or false
1 point

True or false: In Python, an empty list evaluates as false in a Boolean context.

  1. A

    True

  2. B

    False

16
Choose one
1 point

Which statement creates a separate shallow copy of the list numbers so that later appending to the copy does not change the original list?

  1. A

    copy_of_numbers = numbers[:]

  2. B

    copy_of_numbers = numbers

  3. C

    copy_of_numbers = numbers.append(4)

  4. D

    copy_of_numbers = str(numbers)

17
Written response
1 point

What Python type does input() return before the program applies a conversion such as int() or float()?

18
Written response
1 point

What integer value does int(-3.9) produce?

19
Choose one
1 point

A developer is inspecting a string variable named message and wants a representation that is especially useful for debugging, including details such as quotation marks or escape characters when relevant. Which expression should the developer use?

  1. A

    str(message)

  2. B

    repr(message)

  3. C

    format(message)

  4. D

    type(message)

20
Written response
1 point

The variable value may refer to any object or to the absence-of-a-value marker. Enter the exact Python expression recommended for checking whether value refers to that marker.