内置模块相关

 1 # 可使用内置模块 statistics 计算由数字组成的可迭代对象的均值、中间值和众数(mode)
 2 # 可使用内置模块 keyword 检查字符串是不是 Python关键字
 3 import math
 4 import statistics as s
 5 import keyword
 6 
 7 print(math.pi)
 8 print(math.pow(2,3))  # 等价于2**3
 9 nums = [1, 5, 33, 12, 46, 33, 2]
10 # 均值
11 print(s.mean(nums))
12 print('%.4f' % s.mean(nums))
13 # 中间值
14 print(s.median(nums))
15 # 众数
16 print(s.mode(nums))
17 print(keyword.iskeyword('for'))  # True
18 print(keyword.iskeyword('football'))  # False

 

posted @ 2020-10-23 13:34  龚志军Flagon  阅读(80)  评论(0编辑  收藏  举报