新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python隨機(jī)數(shù)模塊的相關(guān)模塊代碼的具體介紹
以下的文章主要是通過(guò) Python隨機(jī)數(shù)模塊的相關(guān)代碼來(lái)介紹Python隨機(jī)數(shù)模塊的相關(guān)模塊,你如果了解了這些相關(guān)的模塊,就會(huì)在Python隨機(jī)數(shù)模塊的實(shí)際應(yīng)用中更好的運(yùn)用,以下是文章的具體介紹。

創(chuàng)新互聯(lián)公司主營(yíng)雨湖網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP開(kāi)發(fā),雨湖h5成都微信小程序搭建,雨湖網(wǎng)站營(yíng)銷推廣歡迎雨湖等地區(qū)企業(yè)咨詢
隨機(jī)整數(shù):
- >>> import random
- >>> random.randint(0,99)
- 21
隨機(jī)選取0到100間的偶數(shù):
- >>> import random
- >>> random.randrange(0, 101, 2)
- 42
隨機(jī)浮點(diǎn)數(shù):
- >>> import random
- >>> random.random()
- 0.85415370477785668
- >>> random.uniform(1, 10)
- 5.4221167969800881
隨機(jī)字符:
- >>> import random
- >>> random.choice('abcdefg%^*f')
- 'd'
多個(gè)字符中選取特定數(shù)量的字符:
- >>> import random
- random.sample('abcdefghij',3)
- ['a', 'd', 'b']
Python隨機(jī)數(shù)模塊中多個(gè)字符中選取特定數(shù)量的字符組成新字符串:
- >>> import random
- >>> import string
- >>> string.join(random.sample(['a','b','c','d','e','f','g','h','i','j'], 3)).r
- eplace(" ","")
- 'fih'
隨機(jī)選取字符串:
- >>> import random
- >>> random.choice ( ['apple', 'pear', 'peach', 'orange', 'lemon'] )
- 'lemon'
洗牌:
- >>> import random
- >>> items = [1, 2, 3, 4, 5, 6]
- >>> random.shuffle(items)
- >>> items
- [3, 2, 5, 6, 4, 1]
以上的文章就是對(duì) Python隨機(jī)數(shù)模塊的相關(guān)的模塊的介紹。
【編輯推薦】
- python隨機(jī)數(shù)生成的代碼的詳細(xì)解析
- Python連接在實(shí)際應(yīng)用中的相關(guān)操作步驟介紹
- Python格式化字符串在實(shí)際操作過(guò)程中的應(yīng)用
- Python正則表達(dá)式中字符串的實(shí)際操作方案介紹
- Python字符和字符串的相關(guān)代碼示例解析
名稱欄目:Python隨機(jī)數(shù)模塊的相關(guān)模塊代碼的具體介紹
本文網(wǎng)址:http://m.fisionsoft.com.cn/article/dhhhdcp.html


咨詢
建站咨詢
