自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python隨機數(shù)模塊的相關模塊代碼的具體介紹

開發(fā) 后端
本文主要介紹的是Python隨機數(shù)模塊中常見的相關模塊,其中包括隨機整數(shù),還有隨機選取0到100間的偶數(shù)的介紹,還有相關模塊的代碼的介紹。

以下的文章主要是通過 Python隨機數(shù)模塊的相關代碼來介紹Python隨機數(shù)模塊的相關模塊,你如果了解了這些相關的模塊,就會在Python隨機數(shù)模塊的實際應用中更好的運用,以下是文章的具體介紹。

隨機整數(shù):

  1. >>> import random  
  2. >>> random.randint(0,99)  
  3. 21 

 隨機選取0到100間的偶數(shù):

  1. >>> import random  
  2. >>> random.randrange(0, 101, 2)  
  3. 42 

 隨機浮點數(shù):

  1. >>> import random  
  2. >>> random.random()   
  3. 0.85415370477785668  
  4. >>> random.uniform(1, 10)  
  5. 5.4221167969800881 

隨機字符:

  1. >>> import random  
  2. >>> random.choice('abcdefg&#%^*f')  
  3. 'd' 

 多個字符中選取特定數(shù)量的字符:

  1. >>> import random  
  2. random.sample('abcdefghij',3)   
  3. ['a', 'd', 'b'] 

 Python隨機數(shù)模塊中多個字符中選取特定數(shù)量的字符組成新字符串:

  1. >>> import random  
  2. >>> import string  
  3. >>> string.join(random.sample(['a','b','c','d','e','f','g','h','i','j'], 3)).r  
  4. eplace(" ","")  
  5. 'fih' 

 隨機選取字符串:

  1. >>> import random  
  2. >>> random.choice ( ['apple', 'pear', 'peach', 'orange', 'lemon'] )  
  3. 'lemon' 

 洗牌:

  1. >>> import random  
  2. >>> items = [1, 2, 3, 4, 5, 6]  
  3. >>> random.shuffle(items)  
  4. >>> items  
  5. [3, 2, 5, 6, 4, 1]  

以上的文章就是對 Python隨機數(shù)模塊的相關的模塊的介紹。

【編輯推薦】

  1. python隨機數(shù)生成的代碼的詳細解析
  2. Python連接在實際應用中的相關操作步驟介紹
  3. Python格式化字符串在實際操作過程中的應用
  4. Python正則表達式中字符串的實際操作方案介紹
  5. Python字符和字符串的相關代碼示例解析
責任編輯:佚名 來源: 博客園
相關推薦

2010-03-18 09:33:46

python隨機數(shù)模塊

2010-03-19 14:44:30

Python模塊級函數(shù)

2010-03-19 11:04:20

python模塊

2010-03-23 09:47:38

Python隨機數(shù)Python隨機字符串

2025-02-17 10:50:37

2010-03-19 14:59:00

python Stri

2010-03-22 10:27:28

Python常用模塊I

2010-03-11 17:40:41

Python語言

2010-03-22 15:58:08

Python模塊功能

2010-03-22 19:41:31

2010-03-12 15:13:41

Python常用模塊

2010-03-16 20:27:52

Python模塊

2011-07-08 15:11:03

JAVA

2010-03-18 17:57:17

Python安裝配置

2023-12-13 10:46:27

2010-02-23 14:41:28

Python模塊

2010-03-12 19:49:11

python 定時器

2010-03-05 10:47:05

Python futu

2010-03-25 13:19:57

Python_ast.

2010-03-23 16:16:21

Python文件
點贊
收藏

51CTO技術棧公眾號