2011-03-04 128 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