Sobes.tech
Junior — Senior

Manipulations with tuples and type checking

livecode

Task condition

Explain what happens in the program: what values are assigned to variables, how the tuple is formed, and what result the isinstance check will return.

def getValue():
    number = 1_999_333
    tup = (number,)
    print(isinstance(tup, int))

if __name__ == "__main__":
    getValue()
  • The variable number receives the integer value 1999333 (underscores are only for readability).
  • tup is created as a tuple containing a single element — the value of number. The notation (number,) is mandatory; otherwise, the parentheses are perceived as regular brackets around an expression.
  • The function isinstance(tup, int) checks whether the object tup is an instance of the class int. Since tup is a tuple, not an integer, the check returns False, and this value is printed to the screen.