在python2中:raw_input会将用户输入的任何内容都存成字符串类型 ''' C:Usersoldboy>python2 Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> name=raw_input('>>>>>>>>>>>>>>>>>>>>>>>>>>>>: ') >>>>>>>>>>>>>>>>>>>>>>>>>>>>: egon >>> >>> >>> >>> print(name) egon
二、格式化输出:
name=input('please input your username:') age=input('please input your age:') print('my name is',name,'my age is',age) print('my name is %s,my age is %s' %(name,age))
''' my name is 输入的用户名,my age is 输入的年龄 '''
print('my name is %s my age is %s' %(18,'egon'))
print('my name is %s my age is %d' %('egon',18)) print('my name is %s my age is %s' %('egon',18)) print('my name is %s my age is %s' %('egon',[1,2,3])) # %s可以接收任意类型的值 print('my name is %s my age is %d' %('egon','xxx')) # %d只能接收数字类型