【python】判断一个字符串是否是数字

def is_number(s):
	try:
		float(s)
		return True
	except ValueError:
		pass
 
	try:
		import unicodedata
		unicodedata.numeric(s)
		return True
	except (TypeError, ValueError):
		pass
 
	return False

str = '1109'
	
if is_number(str):
	print('is number')
else:
	print('is not number')

  

posted on 2018-08-24 11:20  芽衣  阅读(5645)  评论(1编辑  收藏  举报

导航