You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
s.isnumeric only works for ints (all digits). For floats, there is usually no need to wrap float()
if fs.isnumber(): <do x>
else: <do y>
is a slower version of
try:
float(fs)
<do x>
except ValueError:
<do y>
In nearly all cases where we want to know if a string can be converted, we want the converted float, and throwing it away just to call float again is poor practice. In Python, try-except is as legitimate as if-else.
Note: New builtin functions are not 'minor features' and always need major discussion and a high bar for adoption. We are also pretty stringent about new methods for built-in classes.
Feature or enhancement
Proposal:
A string method called .isnumber(), it will check if a string is a float or an integer and return True or False.
Examples:
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: