Python,无效语法(随机模块)

标签 python

from random import *

print randint(1, 100)
print (x)

如果我尝试运行此代码,我会收到一条错误消息,指出“randint”是无效语法。

最佳答案

因为您可能使用的是 python 3,所以您必须将要打印的内容括在括号中:

from random import *
print(randint(1, 100))

关于Python,无效语法(随机模块),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46125065/

相关文章:

python - Jinja 嵌套渲染可变内容

python - 如果python程序的参数是目录,我如何读取每个文件?

python - 使用 Python 的 xlrd 和 xlutils 保留 Excel 格式的问题

python - 使用 AWS Cloudwatch Agent 和 Python 记录自定义指标

python - ManytoManyField 不返回 str 对象

使用 Tkinter 标签更改文本的 Python 引用

python - 如何在Python中的for循环中将数组值分配给列表

python - 网页抓取 - 进入第 2 页

python - 如何检查 2 个数据库是否打开或关闭(一个在 sqlite3 中,另一个在 MySQL 中)- Python 3.3?

python - GDB 7.2 + python : how to get members of anonymous structure?