vendredi 24 mars 2017

write an if statemnet where it checks if a variable is an integer, float or string in python [duplicate]

This question already has an answer here:

Im trying to write a prime number checker in python and I can't write an if statement where if will run code it the result is an integer or not. I think that it should look like this.

x = 2
if result is int:
    print("something")
elif result is float:
    print("something else")
else:
    print("something final")

or this:

x = 2
if result == int:
    print("something")
elif result == float:
    print("something else")
else:
    print("something final")

Both of these bits of code print the statements that are in the else statements. Can anyone help me with the code that will actually work?

Aucun commentaire:

Enregistrer un commentaire