How to check if a string is an integer or a float in Python

1 Answer

0 votes
string = '72834.27'

if string.isdigit():
   print("Integer")
elif string.replace('.','',1).isdigit() and string.count('.') == 1:
   print("Float")
else:
   print("Its is Neither Integer Nor Float")
   
   
   
'''
run:

Float

'''

 



answered Jul 29, 2022 by avibootz
edited Jul 29, 2022 by avibootz

Related questions

3 answers 192 views
1 answer 157 views
2 answers 235 views
2 answers 287 views
2 answers 215 views
1 answer 194 views
...