num = 3.14159
print("{:.2f}".format(num)) # 输出为3.14
num = 123
print("{:5d}".format(num)) # 输出为" 123"
num = 123456.789
print("{:.2e}".format(num)) # 输出为1.23e+05
num = 255
print("{:x}".format(num)) # 输出为"ff"
print("{:o}".format(num)) # 输出为"377"
name = "Alice"
age = 20
print("My name is {0} and I am {1} years old.".format(name, age)) # 输出为"My name is Alice and I am 20 years old."
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python print format函数的颜色与样式设置技巧有哪些