Python编程-基础知识-字符串格式化

1. 简单字符串格式化

 

format = "Hello, how are you doing %s %s!"
values = ("David""Gu")
print format % values

 

Result:

Hello, how are you doing David Gu!

 

format = "PI with seven decimals: %.7f"
from math import pi
print format % pi

 

Result:

PI with seven decimals: 3.1415927

 

 

posted @ 2012-03-19 17:01  Master HaKu  阅读(180)  评论(0编辑  收藏  举报