Variable update

In Listing 1, a Python function updates the values of variables a, b, c, d, and e. The variables intended for arithmetic results are annotated as int, while the variables intended for logical results are annotated as bool. The final values are displayed using print.

Listing 1: Python code that updates the values of a, b, c, d, and e and prints the final values (Question 1).
def update_variables():
    a: int = 9
    a = a + 1
    b: bool = 1 == 1
    c: int = 99 % 10
    d: int = 99 // 10
    e: bool = (not False) or False

    print(
        "a:",
        a,
        "b:",
        b,
        "c:",
        c,
        "d:",
        d,
        "e:",
        e,
    )


update_variables()

What is printed when the code in Listing 1 is executed?

  1. a: 9 b: 1 c: 9 d: 9 e: False
  2. a: 10 b: True c: 9 d: 9 e: True
  3. a: 1 b: True c: 9 d: 9 e: True
  4. a: 10 b: 1 c: 9 d: 9 e: True
  • =: Assignment operator.
  • ==: Equality comparison operator, which produces a Boolean value.
  • %: Modulo operator, which gives the remainder of a division.
  • //: Floor-division operator; for the positive integers used here, it gives the integer quotient.
  • not: Logical negation operator.
  • or: Logical OR operator.

The keywords not and or perform Boolean logic here. They are different from the bitwise operators ~ and |.