0
對不起,我是初學者。但是,像如果我有:測試輸入是字符串而不是數字嗎?
x = eval(input('Enter a value for x: '))
怎樣讓這個如果人輸入一個字符串,而不是數字,將打印"Enter a number"
而不是讓錯誤的。某些類型的if語句,其中:
if x == str():
print('Please enter a number')
else:
print('blah blah blah')
更好地貼近目標將是:我如何檢查是否一個字符串是Python中的號碼是多少?(http://stackoverflow.com/questions/354038/how-do-i - 檢查,如果一個字符串是一個數字在python)或 [你如何檢查一個字符串是否只包含數字 - 蟒蛇](http://stackoverflow.com/questions/21388541/how- DO-您檢查-IF-A-字符串包含專用號碼的Python) – bummi 2014-10-11 22:30:16