#coding:utf-8
name = 'Zed A. Shaw'
age = 8.123 # not a lie
height = 74 # inches
weight = 180 # lbs
eyes = 'Blue'
teeth = 'White'
hair = 'Brown'

print "His name is %s" %name
#这里可以将常量也以这种方式打印出来
#格式化字符数字宽度为10,不够前面用0代替,精度为2
print "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)

如下记录一些学习过程中遇到的知识点:
1.字符串竟然也可以乘以数字,标示重复打印多少遍

print "mh" * 10
mhmhmhmhmhmhmhmhmhmh

2.print语句默认的会在后面加上 换行 加了逗号之后 换行 就变成了 空格
print "hi",
print "my"
hi my
 



http://www.douban.com/note/269665597/,这个里有比较全的格式化字符讲解

相关文章:

  • 2022-12-23
  • 2021-04-02
  • 2021-07-30
  • 2021-12-09
  • 2021-12-09
  • 2022-02-09
  • 2022-02-08
猜你喜欢
  • 2022-01-15
  • 2021-12-18
  • 2021-07-27
  • 2022-01-23
  • 2021-12-18
  • 2021-05-29
相关资源
相似解决方案