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
numberreceives the integer value1999333(underscores are only for readability). tupis created as a tuple containing a single element — the value ofnumber. The notation(number,)is mandatory; otherwise, the parentheses are perceived as regular brackets around an expression.- The function
isinstance(tup, int)checks whether the objecttupis an instance of the classint. Sincetupis a tuple, not an integer, the check returnsFalse, and this value is printed to the screen.