A simple test of a numeric string.
A Python module 'isnumeric'
''' isnumeric.py
test a numeric string s if it's usable for int(s) or float(s)
'''
def isnumeric(s):
'''returns True if string s is numeric'''
return all(c in "0123456789.+-" for c in s)
# test module ...
if __name__ == '__main__':
print(isnumeric('123')) # True
print(isnumeric('-123.45')) # True
print(isnumeric('+3.14')) # True
print(isnumeric('$99.95')) # False
TrustyTony 888 pyMod Team Colleague Featured Poster
Ene Uran 638 Posting Virtuoso
ZZucker 342 Practically a Master Poster
HiHe 174 Junior Poster
robinlrandall 0 Newbie Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
robinlrandall 0 Newbie Poster
TrustyTony 888 pyMod Team Colleague Featured Poster
Gribouillis 1,391 Programming Explorer Team Colleague
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague
BearofNH 104 Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.