今天写程序需要一个功能,判断一个字符串里是否仅包含数字,如'abc521' '123456'这些字符串哪些是紧包含数字,发现了一个很好的方法:
def isNumber(i):
'''
check if a string is number
'''
try:
temp = int(i)
return True
except:
return False
About this article
- Author
- Lerry
- Published
- 2011-12-08
- License
- CC BY-NC-ND 4.0