Checking if input is integer in Python3.7 gives error [duplicate]
Clash Royale CLAN TAG#URR8PPP
Checking if input is integer in Python3.7 gives error [duplicate]
This question already has an answer here:
I am trying to check if the input is integer. But the code is repetedly saying "something else" in each and every input I give. Is something wrong with the code?
x = input("enter:")
if type(x) == int:
print("int")
else:
print("something else")
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
type(input())
str
type('123') is str
type(123) is int
@juanpa.arrivillaga you don't want to edit the question after it's been closed, because it automatically puts it in the reopen queue.
– Jean-François Fabre
59 secs ago
@Jean-FrançoisFabre didn't edit it
– juanpa.arrivillaga
22 secs ago
1 Answer
1
if float(x).is_integer():
# do stuff
type(input())
will always bestr
. Note,type('123') is str
andtype(123) is int
– juanpa.arrivillaga
2 mins ago