1.数学基础计算

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))) #平方根

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值