filmov
tv
CORRECT way to check if Python string is numeric (float or int) 🐍 #shorts

Показать описание
Apply the EAFP (Easier to Ask Forgiveness than Permission)
I show how to write an is_numeric function that correctly handles ints, floats, leading zeros and scientific notation when checking if a Python string is a number. We use try/except and just attempt to convert string to float.
I show how to write an is_numeric function that correctly handles ints, floats, leading zeros and scientific notation when checking if a Python string is a number. We use try/except and just attempt to convert string to float.