Python基础阶段:常用函数

 1 # -*- coding:utf-8 -*-
 2 #   内嵌函数
 3 # abs 返回数值的绝对值
 4 #
 5 # # num = -10
 6 # print(abs(num))
 7 
 8 # # 最大值 max  最小值 min
 9 # print(max(1,2,3))
10 
11 # round(num[,n]) 四舍五入
12 #  , n  四舍五入的位数
13 # p = 3.148
14 # print(round(p,2))
15 #
16 # # pow(x,y)
17 # #返回 x 的 y 次幂
18 # #  x**y
19 # print(pow(2,4))
20  # math模块函数
21  # 导入
22 import math
23  # math.函数名称(参数)
24 p1 = 3.5
25 print(round(p1))
26 print(math.ceil(p1))  #ceil 上取整
27 print(math.floor(p1))  #floor 下取整
28 print(math.sqrt(9))   # 开平方
29 print(math.log(10000,10)) # log(x,base) 以base为基数,x的对数 10的4次幂 =10000
常用数学函数
 1 # -*- coding:utf-8 -*-
 2 
 3 # 导入模块
 4 # random 随机函数 取值在[0,1)之间
 5 import random
 6 
 7 print(random.randint())
 8 
 9 #  random.choice 序列中随机取值
10 
11 set = [1,3,5,8,9,4]
12 print(random.choice(set))
13 
14 # uniform 确定范围之内的随机小数
15 # [x,y]
16 print(random.uniform(1,2))
17 
18 # randint 随机整数
19 
20 # randrange (start,step) 确定区间随机整数,取不到step
21 #     (start,shep,3) # 以3为步长,
22 print(random.randrange(1,13,3))
常用随机函数
# -*- coding:utf-8 -*-

#
# 导入数学
    #import math
#
#
#
# #正弦函数
# #的sin(x)中,x,参数,所接收的,是一个弧度角度
# # PI = 180 pi = 3.14
# #弧度= 30/180 * PI
# #弧度= 1/6 * math.pi
# hudu = math.radians(30)
# result = math.sin(hudu)
# print(result)
三角函数

猜你喜欢

转载自www.cnblogs.com/easyone/p/9418900.html
今日推荐