#1. 打印字符串
print ("My name is %s"%("xiaohu"))
# 2.打印整数
print ("She is %d years old"%(18))
# 3.打印浮点数
print ("Her height is %f m"%(1.83))
# 4.打印浮点数(指定保留小数点位数)
print ("His height is %.2f m"%(1.66))
# 5.指定占位符宽度
print ("Name:%10s Age:%8d Height:%8.2f"%("weihu",25,1.83))
print ("Name:%-10s Age:%-8d Height:%-8.2f"%("weihu",25,1.83))
# 7.指定占位符(只能用0当占位符?)
print ("Name:%-10s Age:%08d Height:%08.2f"%("weihu",25,1.83))
# 8.科学计数法
format(0.0015,'.2e')

运行结果:

  • My name is xiaohu
  • She is 18 years old
  • Her height is 1.830000 m
  • His height is 1.66 m
  • Name: weihu Age: 25 Height: 1.83
  • Name:weihu Age:25 Height:1.83
  • Name:weihu Age:00000025 Height:00001.83