1. 程式人生 > >【python】判斷一個字符串是否是數字

【python】判斷一個字符串是否是數字

val imp erro not 判斷 數字 try false urn

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‘)

  

【python】判斷一個字符串是否是數字