Python格式化输出总结
格式化输出一,使用%占位符
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格式化输出总结
本文链接:http://azwzsj.com/article/gjjdoo.html