Python编程:怎么使用random模块sample()方法

 时间:2024-10-16 22:16:02

1、首先在PyCharm软件中,打开一个Python项目。

Python编程:怎么使用random模块sample()方法

2、在Python项目中,新建并打开一个空白的python文件(比如:test.py)。

Python编程:怎么使用random模块sample()方法

3、在python文件编辑区中,输入:“import random”,导入 random 模块。

Python编程:怎么使用random模块sample()方法

4、再输入:“plist = [2, 3, 4, 5, 6, 7]”,点击Enter键。

Python编程:怎么使用random模块sample()方法

5、输入:“xlist = random.sample(plist, 3)”,点击Enter键。

Python编程:怎么使用random模块sample()方法

6、然后输入:“print(xlist)”,打印出相关数据结果。

Python编程:怎么使用random模块sample()方法

7、在编辑区域点击鼠标右键,在弹出菜单中选择“运行”选项。

Python编程:怎么使用random模块sample()方法

8、在运行结果窗口中查看运行结果,可以看到已经使用了random模块sample()方法。

Python编程:怎么使用random模块sample()方法
  • C语言中的函数如何声明和使用?
  • c语言取余数怎么求
  • C语言的putchar如何使用?
  • 怎么用Python输出hello world
  • codeblocks下面的运行框不见了怎么办
  • 热门搜索
    温州大学怎么样 孙策是怎么死的 李子柒怎么盈利 怎么做凉皮 海蜇头怎么凉拌 小腿酸痛是怎么回事 惠达卫浴怎么样 胸太大怎么办 唱歌跑调怎么办 怎么安装字体