十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
格式化输出一,使用%占位符
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)