判断输入是数字,还是字符串
方法一:
a = input("请输入一个要判断的字符: ") m = n = 0 for i in a: m += 1 if i in ['0','1','2','3','4','5','6','7','8','9']: n += 1 if m == n: print("您输入的是数字:", a) else: print("您输入的是字符串:", a)
方法二:
myInput = input("请输入一个要判断的字符: ") isStr = False for i in myInput: if i in ['0','1','2','3','4','5','6','7','8','9']: continue isStr = True if isStr: print("您输入的是字符串:", myInput) else: print("您输入的是:数字", myInput)