0
Is there a way to use .isdigit() with strings that could contain negative numbers?
Would the best way to do this be to check for the "-" at the start of the string, strip it and then reapply it after the .isdigit() check? This seems a bit convoluted.
2 Respuestas
+ 6
use lstrip() function first. This will work for positive and negative numbers.
str = "-2137"
result = str.lstrip('-').isdigit()
0
Thanks!