python2.7实现控制台输入input

输入字符串

your_input=input('please input your name:')
print('your name is :', your_input)

please input your name:wang
回车提示错误
输入数字的情况

your_input=input('please input a num:')
print('the num is :',your_input)

please input a num:123
(‘the num is :’, 123)
python2.7在input后返回一个int数字

your_input=input('please input a num:')
if your_input ==1:
    print('good luck.')
elif your_input == 2:
    print('see you.')
else:
    print('continue.')

please input a num:2
see you.
python3.5返回的是一个string类型的

#或者在input前面加int(input())
your_input=input('please input a num:')#return a string
if your_input == '1':#两种方式转化成str比较
    print('good luck.')
elif your_input == str(2):
    print('see you.')
else:
    print('continue.')

你可能感兴趣的:(python学习)