dimanche 29 juillet 2018

isinstance function in if statement python

As part of a lcm program I'm creating, I want a condition to determine whether the result of an expression is integer or float. After looking online, I found the isinstance function, which outputs a boolean. I want to be able to use that in the statement, and execute the respective . How exactly do I code it? This is an example:

num=input("Enter a number: ")
if isinstance(num,int):
  print("Float")
else:
  print("Integer")

Aucun commentaire:

Enregistrer un commentaire