2011-03-04 124 views
0

为什么是这样的:为什么语法错误?

# other stuff... 
print str(checksum)+" "+ranswer+".0000000000" 

给语法错误在Python 3,即使在Python 2.5正常工作?

增加:

有谁告诉我什么是strip(something)在Python 3等价?

谢谢,它现在固定。

回答

4

打印在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' 
1

在Python 3中,print是一个函数,而不是关键字。

做到这一点:print(str(checksum)+" "+ranswer+".0000000000")

+0

感谢你能请我加入的查询? – Quixotic 2011-03-04 02:35:47

+0

如果您正在寻找字符串上的strip()方法,那么它仍然存在。否则,我不知道一个strip函数。 – dappawit 2011-03-04 02:39:45

+0

我已经回答了你原来的问题,接受我的答案如何?如果您还有其他问题,可以单独询问。 – dappawit 2011-03-04 02:43:32