【问题标题】:print sep='' not working in Python 2.7.8print sep='' 在 Python 2.7.8 中不起作用
【发布时间】:2015-06-27 14:06:20
【问题描述】:

作为试用,我在 Python 2.7.8 中使用了以下代码:

print 'one', 'two', 'three', sep =''

我得到的信息是

SyntaxError: 无效语法

我想要的输出是

一二三

【问题讨论】:

  • 是否需要编辑问题?无论如何,如果它对某人有所帮助,那很好。
  • 这是必要的,因为你没有格式化你的代码,这使得它难以阅读

标签: python string python-2.7


【解决方案1】:

print() 函数是 Python 3 的一项功能,但您可以像这样在 Python 2 上获得它

>>> from __future__ import print_function
>>> print('one', 'two', 'three', sep='')
onetwothree

【讨论】:

  • 没问题,如果您认为它解决了所有问题,请随时接受
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-03
  • 1970-01-01
  • 2014-04-02
  • 1970-01-01
相关资源
最近更新 更多