-2

This does not print anything for some reason.


main = 60

x = isinstance(main, int)

if x == ("True"):  
   print("True") 

elif x == ("False"):  
   print("False")

  • 2
    `x` is not `("True")` or `("False")` it's `True` or `False` – Kraigolas Mar 03 '21 at 21:35
  • Yes, you're comparing a bool and a string, note that the parentheses do not create a tuple here in the absence of a comma, although they do reduce clarity – Chris_Rands Mar 03 '21 at 21:38

1 Answers1

1

The boolean value which is returned by the isinstance() function is not a string, but (as you may been able to guess) a boolean.

To rewrite the code provided:

main = 60
x = isinstance(main, int)
if x is True:
    print("True")
elif x is False:
    print("False")

However, since booleans can be conditions themselves, and isinstance() returns a boolean, I would recommend this approach:

main = 60
if isinstance(main, int):
    print("True")
else:
    print("False")

Alternatively, even simpler:

main = 60
print(isinstance(main, int))
Jacob Lee
  • 4,405
  • 2
  • 16
  • 37