【发布时间】:2011-03-04 02:26:46
【问题描述】:
为什么会这样:
# other stuff...
print str(checksum)+" "+ranswer+".0000000000"
在 Python 3 中给出语法错误,即使它在 Python 2.5 中运行良好?
添加:
谁能告诉我在 python 3 中 strip(something) 的等价物是什么?
谢谢,现在修好了。
【问题讨论】:
标签: python python-3.x
为什么会这样:
# other stuff...
print str(checksum)+" "+ranswer+".0000000000"
在 Python 3 中给出语法错误,即使它在 Python 2.5 中运行良好?
添加:
谁能告诉我在 python 3 中 strip(something) 的等价物是什么?
谢谢,现在修好了。
【问题讨论】:
标签: python python-3.x
print 是 Python3 中的一个函数。使用它是print(...)没有任何东西叫做strip(something)。但是您可能会寻找“字符串对象上的strip() 方法”。它在 Python3 中可用。
strip(...)
S.strip([chars]) -> str
Return a copy of the string S with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
你可以这样使用它:
>>> ' Philando Gullible '.strip()
'Philando Gullible'
>>> 'aaaXXXbbb'.strip('ab')
'XXX'
【讨论】:
在 Python 3 中,print 是一个函数,而不是关键字。
这样做:print(str(checksum)+" "+ranswer+".0000000000")
【讨论】: