input() 函数接收输入字符
int() 获取数值输入
stu = input("please input: ") print("output: ",stu) a = "sdf gret try w35r re" a += "please input:" stu = input(a) #如果提示字符太长,通过赋值变量输出 print("output: ",stu) stu = int(input("please input digit: ")) #只能够输入数字,否则会出错 print("output: ",stu)
please input: rweq output: rweq sdf gret try w35r replease input:greggre output: greggre please input digit: 3242321 output: 3242321 #错误实例 please input: ew output: ew sdf gret try w35r replease input:rew output: rew please input digit: erw Traceback (most recent call last): File "/Users/sw-diag/Desktop/SW-USERS/Lin/pythonProject/main.py", line 122, instu = int(input("please input digit: ")) #只能够输入数字,否则会出错 ValueError: invalid literal for int() with base 10: 'erw'