#coding:utf-8name = ‘Zed A. Shaw‘age = 8.123 # not a lieheight = 74 # inchesweight = 180 # lbseyes = ‘Blue‘teeth = ‘White‘hair = ‘Brown‘ print "His name is %s" %name#这里可以将常量也以这种方式打印出来#格式化字符数字宽度为10,不够前面用0代替,精度为2print "His age is %010.2f" %10
#r是不管是什么都打印出来 print "His height is %r inches and weight is %d lbs" %(height,weight)
print "If I add %d,%d and %d is %d" %(age,height,weight,age+height+weight) http://www.douban.com/note/269665597/,这个里有比较全的格式化字符讲解
时间: 2024-10-11 22:36:30