shivency

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1、输出格式化/多个输出格式化

1 x= 4
2 y= 12.5
3 
4 print 'the rabbit is %d',x
5 print 'the rabbit is %d years old',x
6 print '%f is average',y
7 print '%f * %d' %(y,x)
8 print '%f * %d is %f' %(y, x, y*x)

4~6行是输出格式化,7~8行为多个输出格式化

下面是结果

1 the rabbit is %d 4
2 the rabbit is %d years old 4
3 %f is average 12.5
4 12.500000 * 4
5 12.500000 * 4 is 50.000000


然后有两个问题:

1、为什么python中字符串乘负数会为空字符串而不报错?

2、如何输出格式化使%8,打印出0008?

posted on 2013-06-11 10:56  shivency  阅读(204)  评论(0编辑  收藏  举报