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 178 views
1 answer 151 views
2 answers 219 views
2 answers 261 views
2 answers 202 views
1 answer 184 views
...