小白教程
所有教程
关于
Search
172.71.254.94
172.71.254.94
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 func number shuffle”的源代码
本页内容
上一节:
Python3_func_number_choice
下一节:
Python3_func_number_random
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:shuffle(x[, random])}}[[Category:python random|5]] = Python3 shuffle() 函数 = [[python3 number|Python3 数字]] == 描述 == '''shuffle()''' 方法将序列的所有元素随机排序。 == 语法 == 以下是 shuffle() 方法的语法: <sample title="" desc="" lang="python" hererun="1"> import random random.shuffle (lst ) </sample> '''注意:'''shuffle() 是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用该方法。 == 参数 == * lst -- 列表。 == 返回值 == 返回 None。 以下展示了使用 shuffle() 方法的实例: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import random list = [20, 16, 10, 5]; random.shuffle(list) print ("随机排序列表 : ", list) random.shuffle(list) print ("随机排序列表 : ", list) </sample> 以上实例运行后输出结果为: <sample title="" desc="" lang="python" hererun="1"> 随机排序列表 : [20, 5, 16, 10] 随机排序列表 : [5, 20, 10, 16] </sample> [[python3 number|Python3 数字]]
返回至“
Python3 func number shuffle
”。
上一节:
Python3_func_number_choice
下一节:
Python3_func_number_random