num =-5print(num)print(abs(num))#绝对值abs() = 5print(pow(5,2))#次方^pow() = 25print(5**2)#次方,同上 = 25print(max(7,9,5))#which is higher = 9print(round(3.8),"\n")#四舍五入 = 4from math import*print(floor(3.8))#向下取整 = 3print(ceil(3.8))#向上取整 = 4print(sqrt(36),"\n")#开根号 = 6.0(保留一位小数)import math
print(math.cos(math.pi/4))#计算cos(pi/4)print(math.log(1024,2),"\n")#计算log2(1024) = 10
-5
5
25
25
9
4
3
4
6.0
0.7071067811865476
10.0
随机函数random
import random
p =["a","b","c","d","e","f"]print(p)
random.shuffle(p)#打乱p元素顺序print(p)print(random.choice(p))#随机选取p中一个元素print(random.random())#随机输出0~1的浮点数print(random.uniform(1,10))#随机输出1~10的浮点数print(random.randrange(0,101,2))#随机选取0~100的偶数print(random.randint(50,100))#随机生成50~100整数print(random.sample(range(100),10))#随机输出0-99中10个数字
from datetime import date
now = date.today()print(now)#2019-01-28import time
print(time.time())#时间戳print(time.localtime(time.time()))print(time.asctime(time.localtime(time.time())))#格式化时间print(time.strftime('%Y-%m-%d %H:%M:%S %w-%Z',time.localtime()))#完整日期 时间 星期时区print("running time is ",time.perf_counter(),"s")#程序运行时间,或者 time.process_time()
2019-01-28
1548666578.0288482
time.struct_time(tm_year=2019, tm_mon=1, tm_mday=28, tm_hour=17, tm_min=9, tm_sec=38, tm_wday=0, tm_yday=28, tm_isdst=0)
Mon Jan 28 17:09:38 2019
2019-01-28 17:09:38 1-CST
running time is 0.084361643 s