【问题标题】:vscode error on "end" parameter of print function in pythonpython中打印函数的“end”参数上的vscode错误
【发布时间】:2019-08-24 14:43:48
【问题描述】:

vscode IDE 在 python 语言中使用 { print(i,end=' ') } 时显示错误

我用过pycharm IDE,它工作正常...

def showDivisor(number):
    for i in range(1, number+1):
        if number % i == 0:
            print(i, end=' ')

showDivisor(24)

enter image description here

【问题讨论】:

  • 你在 Python 2 上运行。
  • 我用的是python 3,你可以在附图的第一行终端输出中看到
  • 该行中没有任何内容表示特定的 Python 版本。另一方面,语法错误对于在 Python 2 上使用 Python 3 print() 函数运行代码很典型。

标签: python printing visual-studio-code


【解决方案1】:

在 Python 3.6.5 中运行您的代码 => 没问题。

使用 Python 2.7.13 运行 => 给定的语法错误。

点击状态行左下角的Python字并选择Python 3.x

您可以通过查看工作区的设置来检查使用了哪个 python 解释器。

【讨论】:

    【解决方案2】:

    您正在通过 Code Runner 扩展执行代码,而不是 Python 扩展,因此为后者选择的解释器不会通知前者。要么使用 Python 扩展通过 Run Python File in Terminal 运行你的代码,要么你需要配置 Code Runner 扩展以使用 Python 3。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多