python basic application --- formatted output

python formatted output, they are not quite understand, and now understand a little, write a blog specifically for this purpose to record it, so that they will forget any time to view,

Program body


#格式化输出之一
name = input("pls input your name:")
age = input('pls input your age:')
info = '''
------------------info of {_name}---------------------
Name: {_name}
Age: {_age}
-----------------------end----------------------------
'''.format(_name=name,
           _age=age)
print(info)

#输出结果 
pls input your namewang
pls input your age:22

------------------info of wang---------------------
Name: wang
Age: 22
-----------------------end----------------------------

#格式化输出之二
name = input('pls input your name:')
age = input('pls input your age:')
info='''
---------------info of %a---------------
Name: %a
Age: %a
---------------end----------------------
'''%(name,name,age)
print(info)

#程序输出结果
pls input your name:wang
pls input your age:22

---------------info of 'wang'---------------
Name: 'wang'
Age: '22'
---------------end----------------------

Get used currently in use, that was one of the more convenient format, I am also doing so.

Guess you like

Origin www.cnblogs.com/wang50902/p/11818073.html