1.整数计算
x=4
y=5
z=x+y
print("Output #2:Four plus five equals {0:d}.".format(z))
#0 代表方法中第一个参数。
#d 代表将参数转为整数
2.数组。
a=[1,2,3,4]
b=["first","second","third","fourth"]
c=a+b
print("{0},{1},{2}".format(a,b,c))
#[1, 2, 3, 4],['first', 'second', 'third', 'fourth'],[1, 2, 3, 4, 'first', 'second', 'third', 'fourth']
#数组合并。
3.整数计算
x=9
print({0}.format(x))
print({0}.format(3**4)) #3的4次方;
print({0}.format(int(8.3)/int(2.7))) #8/2;
4.浮点数计算
print("{0:.3f}".format(8.3/2.7)) #3.074
y=2.5*4.8
print("{0:.1f}".format(y)) #保留1位小数
r=8/float(3)
print("{0:.2f}".format(r)) #保留2位小数
5.Math函数包。
#!/usr/bin/env python3
from math import exp,log,sqrt
print("{0:.4f}".format(exp(3))) #e的乘方。
print("{0:.2f}".format(log(4))) #自然对数
print("{0:.1f}".format(sqrt(81))) #平方根