python 格式化输出 day2

#格式化输出
# % s d   //s是str  d是int
name = input('输入你的名字:')
age = input('输入你的年龄:')
height = input('输入你的身高:')
msg = "我叫%s, 今年%s ,身高%s ,学习进度为3%%
" %(name,age,height) print(msg) ##################
%是占位符,s是要替换的字符串,d是要替换的数字,,要按照对应的顺序输出 ################## 执行结果: F:\python3.6\python.exe F:/python_workdir/oldboy/while.py 输入你的名字:大哥 输入你的年龄:18 输入你的身高:178 我叫大哥, 今年18 ,身高17, 学习进度为3%

  

name = input('输入你的名字:')
age = input('输入你的年龄:')
height = input('输入你的身高:')
msg = '''------info of %s ---------
我叫  : %s
今年  : %s 
身高  : %s
--------end -------  
''' %(name, name, age, height)
print(msg)

###############

F:\python3.6\python.exe F:/python_workdir/oldboy/while.py
输入你的名字:alice
输入你的年龄:18
输入你的身高:180
------info of alice ---------
我叫  : alice
今年  : 18 
身高  : 180
--------end ------- 

注意:一定是要按照对应的顺序,占位符可以多次使用(name)

  

猜你喜欢

转载自www.cnblogs.com/zstcl/p/9425320.html