value = 'ad.41.bd'
if len(value) == len(value.strip({0,1,2,3,4,5,6,7,8,9})):
# no numbers
else:
# numbers present
There a cleaner way of detecting numbers in a string in Python?
What about this?
import re
if not re.search('\d+', value):
# no numbers
else:
# numbers present
To detect signs in the numbers, use the ?
operator.
import re
if not re.search('-?\d+', value):
# no numbers
else:
# numbers present
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With