數(shù)字類型轉(zhuǎn)換
int(x)?將x轉(zhuǎn)換為一個整數(shù)耳胎。
float(x)?將x轉(zhuǎn)換到一個浮點數(shù)盆繁。
complex(x)?將x轉(zhuǎn)換到一個復(fù)數(shù),實數(shù)部分為 x砚亭,虛數(shù)部分為 0。
complex(x, y)?將 x 和 y 轉(zhuǎn)換到一個復(fù)數(shù)殴玛,實數(shù)部分為 x捅膘,虛數(shù)部分為 y。x 和 y 是數(shù)字表達式族阅。
數(shù)學(xué)函數(shù)
使用math庫前篓跛,用import導(dǎo)入該庫>>> import?math
隨機數(shù)函數(shù)
random.random()? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 返回0與1之間的隨機浮點數(shù)
random.uniform(a,b)? ? ? ? ? ? ? ? ? ? ? ? ? ? ?返回a與b之間的隨機浮點數(shù)
random.randint(a,b)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 返回一個隨機的整數(shù)
random randrange([start],stop[,step])? ?返回指定遞增基數(shù)集合中的一個隨機數(shù)
random.choice(sequence)? ? ? ? ? ? ? ? ? ? 從sequence中返回一個隨機數(shù),sequence可以是列表,元組或字符串
random.shuffle([])? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 將列表中的元素打亂順序? ?
random.sample(sequence,K)? ? ? ? ? ? ? ? 從指定序列中隨機獲取K個元素作為一個片段返回