发布时间:2019-09-18 07:26:13编辑:auto阅读(1599)
格式化输出一,使用%占位符
name = input("请输入您的姓名") age = int(input("请输入您的年龄")) job = input("请输入您的工作") hobby = input("请输入您的爱好") msg = ''' ====== Info of %s ====== name : %s age : %d job : %s hobby : %s ====== end ====== ''' % (name, name, age, job, hobby) print(msg)
格式化输出二,使用字典占位符
dic = {"name":"ghl","age":"24","job":"sre","hobby":"cycling"} name = input("请输入您的姓名") age = int(input("请输入您的年龄")) job = input("请输入您的工作") hobby = input("请输入您的爱好") msg = ''' ====== Info of %(name)s ====== name : %(name)s age : %(age)s job : %(job)s hobby : %(hobby)s ====== end ====== ''' % dic print(msg)
%在格式化输出里面作为字符串使用的时候,使用%%
msg = '我叫%s,今年%d,学习进度5%%' %("ghl",18) print(msg)
上一篇: Python目录下中没有Script文件
下一篇: Python Paste 学习笔记
47840
46386
37279
34731
29312
25970
24909
19949
19541
18026
5790°
6411°
5926°
5960°
7063°
5910°
5942°
6437°
6404°
7776°