1、第一种方式:
root@kali:~/python# vim userinput.py
#!/usr/bin/python
#--*-- coding:utf-8 --*--
Name = raw_input('please your name:\n')
Age = raw_input('please your age:\n')
Sex = raw_input('please your sex:\n')
Job = raw_input('please your job:\n')
print '---------------------------------------'
print 'Information of company staff:\n'
print ' Name:',Name
print ' Age: ',Age
print ' Sex:',Sex
print ' Job:',Job
root@kali:~/python# python userinput.py
please your name:
xuweiyy
please your age:
23
please your sex:
male
please your job:
securitior
---------------------------------------
Information of company staff:
Name: xuweiyy
Age: 23
Sex: male
Job: securitior
2、第二种方式:使用'''............'''
root@kali:~/python# vim userinput.py
#!/usr/bin/python
#--*-- coding:utf-8 --*--
name = raw_input('Name:')
age = raw_input('Age:')
sex = raw_input('Sex:')
job = raw_input('Job:')
print '------------------------------\n'
#print '\tName:',name,'\n\tAge:',age,'\n\tSex:',sex,'\n\tJob:',job
print '''\tName: %s
\tAge: %s
\tSex: %s
\tJob: %s''' % (name,age,sex,job)
~
root@kali:~/python# python userinput.py
Name:xuweitt
Age:23
Sex:male
Job:workor
------------------------------
Name: xuweitt
Age: 23
Sex: male
Job: workor
root@kali:~/python#
3、在raw_input('')输入特定类型
root@kali:~/python# vim userinput.py
#!/usr/bin/python
#--*-- coding:utf-8 --*--
name = raw_input('Name:')
age = int(raw_input('Age:')) //输入特定的整型数字类型
sex = raw_input('Sex:')
job = raw_input('Job:')
print '------------------------------\n'
#print '\tName:',name,'\n\tAge:',age,'\n\tSex:',sex,'\n\tJob:',job
print '''\tName: %s
\tAge: %s
\tSex: %s
\tJob: %s''' % (name,age,sex,job)
root@kali:~/python# python userinput.py
Name:www
Age:dd
Traceback (most recent call last):
File "userinput.py", line 4, in
age = int(raw_input('Age:'))
ValueError: invalid literal for int() with base 10: 'dd'
root@kali:~/python# python userinput.py
Name:www
Age:23
Sex:33
Job:44r
------------------------------
Name: www
Age: 23
Sex: 33
Job: 44r
root@kali:~/python#