1、raw_input
python2.7用户输入字符串的话用raw_input。如果使用input输入字符串的话需要先把字符串放到变量中才可,但是用input输入数字的话是可以直接输入的,所以说在python2.x中只用raw_input
>>> user_input=raw_input("your name:")
your name:sx
>>> print user_input
sx
>>> user_input=input("your name:")
your name:sx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'sx' is not defined
>>> name='sx'
>>> user_input=input("your name:")
your name:name
>>> print user_input
sx
>>> user_input=input("your name:")
your name:3
>>> print user_input
3
2、input
python3.5中用户输入使用input
#coding=utf-8__author__='songx'
user_input=input("input you name:")
print (user_input)
注:raw_input和input都默认接收的是字符
3、%s、%d、%f
%s表示字符占位符
%d表示数字占位符
%f表示浮点数占位符
(1)%s

1 #coding=utf-8 2 name=input("input your name:") 3 age=input("input your age:") 4 job=input("input your job:") 5 msg='''Infomation of user %s 6 ----------------------- 7 Name:%s 8 Age:%s 9 Job:%s 10 ----------End----------''' %(name,name,age,job) 11 print (msg)
(2)%d

1 #coding=utf-8 2 name=input("input your name:") 3 age=int(input("input your age:")) #把输入的年龄强制转换成整数 4 job=input("input your job:") 5 msg='''Infomation of user %s 6 ----------------------- 7 Name:%s 8 Age:%d 9 Job:%s 10 ----------End----------''' %(name,name,age,job) 11 print (msg)
(3)%f

1 #coding=utf-8 2 name=input("input your name:") 3 age=int(input("input your age:")) #把输入的年龄强制转换成整数 4 job=input("input your job:") 5 msg='''Infomation of user %s 6 ----------------------- 7 Name:%s 8 Age:%f 9 Job:%s 10 ----------End----------''' %(name,name,age,job) 11 print (msg)