1. 程式人生 > >格式化時間和 時間撮 random

格式化時間和 時間撮 random

pre order cal amp sample 先進先出 rand fault ret

. collections
namedtuple: 命名元組. 創建類
Counter: 計數器
deque: 雙向隊列
stack: 棧 先進後出
queue: 隊列 先進先出
OrderedDict 有序字典. 浪費內存
defaultdict: 默認值字典
d = defaultdict(callable)
ret = d.get("周潤發")

ret是 callable()

2. time模塊
1. 時間戳. float 數字. 1970-01-01 00:00:00
2. 格式化時間. %Y-%m-%d %H:%M:%S %Y-%m-%d
3. 結構化時間. 把時間拆分了。
時間戳 -> 格式化時間
f = 10086
st = time.localtime(f)
s = time.strftime("%Y-%m-%d %H:%M:%S", st)
格式化時間 -> 時間戳
s = "2018-01-01 12:58:46"
st = time.strptime(s, "%Y-%m-%d %H:%M:%S")
f = time.mktime(st)

sleep()

. random
random.randint(start, end) [start, end]隨機整數
random.choice() 隨機選擇
random.sample() 隨機選擇n個
. os和sys
os 和操作系統相關
sys 和解釋器相關的
sys.path.clear()

格式化時間和 時間撮 random