总结:
1、类似于C语言的格式化输出,先写转换符,再写待转换的对象。
2、与C语言不同的是,转换符和待转换的对象之间,不能用逗号分隔。
1 #!/usr/bin/env python
2
3
4 #print digital variable
5 p = 10
6 x = 20
7 print("p=%d x=%d" %(p,x))8
9 #print string object
10 format = "Hello , %s. %s enough for ya?"
11 values = (‘world‘, ‘Hot‘)12 print(format%values)13
14 #print dictionary object
15 phonenum = {‘Beth‘: ‘9102‘, ‘Alice‘:‘2341‘, ‘Cecil‘:‘3258‘}16 print("Cecil‘s phone number is %(Cecil)s"%phonenum)
原文地址:http://www.cnblogs.com/zhouhaibing/p/7442183.html