婷婷同学_
1、格式符例如:a = 'test'print 'it is a %s' %(a)打印的结果就是 it is a test2、单独看%,是一个运算符号,求余数。例如:求模运算,相当于mod,也就是计算除法的余数,比如5%2就得到1。扩展资料:python中%常用的操作有%s,%d,%r等%s,%r,%d分别表示字符串以str(),rper(),以及十进制整数表示,%f表示结果为浮点型。1、%f 浮点型import math %a.bf,a表示浮点数的打印长度,b表示浮点数小数点后面的精度 ,%f时表示原值,默认是小数点后5位数 。 print "PI=%f" % math.pioutput: PI=3.141593 只是%9f时,表示打印长度9位数,小数点也占一位,不够左侧补空格print "PI=%9f" % math.pioutput: PI=_3.141593 2、%d 整型[python] view plain copynum=14 #%d打印时结果是14 3、%s 字符串[python] view plain copystring="hello" %s打印时结果是hello