2014-11-14 78 views
1

當我使用九月參數在Python 2.7.3,它顯示錯誤的Python 2.7.3:九月參數顯示錯誤

例如: -

 >>>print ("Hello","World",sep ="**") 
      File "<stdin>", line 1 
      print ("Hello","World",sep ="**") 
         ^
      SyntaxError: invalid syntax 

回答

0

您需要鍵入此線第一個:

from __future__ import print_function 

使print成爲函數,並允許傳遞這樣的參數。

6

在Python 2.x中,與Python 3.x不同,print不是函數,而是語句描述的here。基本上,這意味着print被視爲關鍵字(如for),並不像您從Python 3.x中知道的print函數那麼強大。特別是,它不支持sep關鍵字參數。

使用:

from __future__ import print_function 

您可以print的行爲如同在Python 3.x中的print功能

否則,你可以做到同樣的事情,沒有與從__future__導入print_function

print "*".join(["Hellow", "World"])