+ 1
How do you take an input in python and verify its type and print accordingly if it is integer, float or string?
for this , you need to take input and print the input is of type integer/string/float/something else
5 Respostas
+ 4
An input() entry in Python is always of string type ^^
+ 4
you are right visph
+ 3
def number(n):
try:
if '.' in n:
n = float(n)
else:
n = int(n)
except:
pass
finally:
return n
n = input()
print(type(number(n)))
# you can avoid the 'except' statement, but I put it for showing the complete 'try' structure ;)
+ 1
yes i know. that is where the problem lies.. i got this question in a competition.. i could figure out a large method using try and except but i want a better solution
0
nice thank you