3.11 random,calendar

print(random.random())#大于0且小于1之间的float 小数
print(random.uniform(1,5))#1-5之间的浮点数
print(random.randint(1,4))# [1,4]1-4 和之间的数都可以取到
print(random.randrange(1,10,2))# 顾头不顾尾,取奇数
print(random.choice([1,2,3]))#随机取
print(random.sample(['1',2,3,4],3))#随机取,返回一个列表,即使里面为元组,集合,也会返回一个列表
li = [i for i in range(10)]
random.shuffle(li)
print(li)
输出结果:
[1, 6, 0, 5, 3, 4, 9, 7, 2, 8]

calendar

import calendar
cal = calendar.month(2019,8)
print(cal)
输出结果:
        August 2019
Mo Tu We Th Fr Sa Su
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

猜你喜欢

转载自www.cnblogs.com/pythonblogs/p/11210693.html