python格式化输出

一、输出

print('Hello, World!')

二、格式化输出

1、占位符:%

2、表示

1)%s,代表string

2)%d,代表dight

3)%f,代表float

name = input("请输入姓名:")
age = int(input("请输入年龄:"))
info = """---------info %s-----------
姓名:     %s
年龄:     %d
------------end-------------
"""
print(info % (name, name, age))
"""
结果:
请输入姓名:tom
请输入年龄:24
---------info tom-----------
姓名:     tom
年龄:     24
------------end-------------
"""

 4)%%,转义

print('中奖率:%d%%' % 5)   # 中奖率:5%
原文地址:https://www.cnblogs.com/wt7018/p/10745060.html