黄色电影一区二区,韩国少妇自慰A片免费看,精品人妻少妇一级毛片免费蜜桃AV按摩师 ,超碰 香蕉

Python choice() 函數(shù)

python choice() 函數(shù)

python number(數(shù)字)python number(數(shù)字)

choice() 方法返回一個列表,元組或字符串的隨機(jī)項(xiàng)。

 

1. 語法

以下是 choice() 方法的語法:

import random

random.choice( seq  )

注意:choice()是不能直接訪問的,需要導(dǎo)入 random 模塊,然后通過 random 靜態(tài)對象調(diào)用該方法。

 

2. 參數(shù)

  • seq -- 可以是一個列表,元組或字符串。

 

3. 返回值

返回隨機(jī)項(xiàng)。

 

4. 實(shí)例

以下展示了使用 choice() 方法的實(shí)例:

#!/usr/bin/python
import random

print "choice([1, 2, 3, 5, 9]) : ", random.choice([1, 2, 3, 5, 9])
print "choice('a string') : ", random.choice('a string')

以上實(shí)例運(yùn)行后輸出結(jié)果為:

choice([1, 2, 3, 5, 9]) :  2
choice('a string') :  n

python number(數(shù)字)python number(數(shù)字)

下一節(jié):python randrange() 函數(shù)

python 教程

相關(guān)文章