python - 简单的问题:在python3 env中,为什么不能运行简单的打印?
问题描述
print("hello", end="")
输出:
[Running] python -u "/home/a/code/projects/project1.py"
File "/home/a/code/projects/project1.py", line 1
print("hello", end="")
^
SyntaxError: invalid syntax
设置.json
{
"python.linting.pylintEnabled": false,
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.pydocstyleEnabled": false,
"python.pythonPath": "/usr/bin/python3.6"
}
一直在查找为什么代码在 vscode 中的旧版 python 上运行...无法弄清楚。
解决方案
那是因为您使用的是 Python 2:
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello", end="")
File "<stdin>", line 1
print("hello", end="")
^
SyntaxError: invalid syntax
在 Python3 中它不会发生:
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello", end="")
hello>>>
推荐阅读
- c# - EFCore 2.2 找不到 CLR 类型“表达式 []”的关系类型的映射
- sql - 按每个数字的倍数的值分组
- java - viewHolder.setItemClickListener() 不工作
- swift - Swift 扩展仅在符合 Class AND 协议时
- apache-kafka - 无法设置 kerberized kafka 代理:使用 Zookeeper 仲裁成员进行身份验证时出错:仲裁成员的 saslToken 为空
- jenkins - 可以在 Jenkins 中禁用“归档工件”吗?
- reactjs - 使用 react-testing-library 选择子组件
- php - PHP代码没有输出我需要的东西。我怎样才能解决这个问题?
- jquery - 如何在 html 中的图像标签中调用 Jquery 变量
- javascript - JavaScript:将未知数量的参数从一种方法传递给另一种方法