[New-bugs-announce] [issue43808] Add .isfloat() method to str
JimmyCarlos
report at bugs.python.org
Sun Apr 11 10:53:35 EDT 2021
New submission from JimmyCarlos <jonathansagnella at yahoo.com>:
Hello Python Community!
One feature I think would be helpful would be a method to see if a str can be safely converted into a float. Currently, this is not doable without a long regex or a try-except block, as numbers like "-3.52" contain non-numeric symbols.
My suggestion is to make a new boolean method on the str class. Code-wise, it would behave quite similarly to this code:
def isfloat(s:str) -> bool:
try:
float(s)
return True
except:
return False
I appreciate your feedback, so what do you all think?
----------
messages: 390785
nosy: JimmyCarlos
priority: normal
severity: normal
status: open
title: Add .isfloat() method to str
type: enhancement
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43808>
_______________________________________
More information about the New-bugs-announce
mailing list