Checking if input is integer in Python3.7 gives error [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash 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()) will always be str. Note, type('123') is str and type(123) is int
– juanpa.arrivillaga
2 mins ago



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

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS