Mr.*_*Mr. 5 python linux opensuse python-2.7
我有一个奇怪的错误使用sep,file(等)python print()函数的参数.我试着把它谷歌出来,dag around stackoverflow,并阅读python的文档,但我没有想到什么.我附上了一个简单的片段,我会非常感谢任何帮助.
# python
Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("blah"*10, sep=" | ")
File "<stdin>", line 1
print("blah"*10, sep=" | ")
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
cda*_*rke 11
尝试:
from __future__ import print_function
Run Code Online (Sandbox Code Playgroud)
第一
在2.x系列中,print是一个声明,而在3.x中它是一个函数.如果您希望2.6+ print作为函数使用from __future__ import print_function,则将其用作第一个import语句.
期待代码打破
| 归档时间: |
|
| 查看次数: |
4237 次 |
| 最近记录: |