0
去過試圖從幾天的學習Python,遇到了一個語法錯誤,但似乎在我從學習教程工作,這裏的代碼末=」'Python語法錯誤
def func(a):
for i in range(a,10):
print(i,end=' ')
FUNC(2)
和錯誤
print(i,end=' ')
^
SyntaxError: invalid syntax
去過試圖從幾天的學習Python,遇到了一個語法錯誤,但似乎在我從學習教程工作,這裏的代碼末=」'Python語法錯誤
def func(a):
for i in range(a,10):
print(i,end=' ')
FUNC(2)
和錯誤
print(i,end=' ')
^
SyntaxError: invalid syntax
在Python 3這應該工作幾乎正常,但是這是不行的Python 2中,因爲它是這裏的不同語法修改,以不同Python版本
def func(a):
for i in range(a,10):
print(i,end=' ')
>>> func(1)
>>> 1 2 3 4 5 6 7 8 9
def func(a):
for i in range(a,10):
print i, # Trailing comma to signify not to start a new line
>>> func(1)
>>> 1 2 3 4 5 6 7 8 9
附加細節
https://docs.python.org/3/whatsnew/3.0.html#common-stumbling-blocks
代碼
嘗試'python --version',你肯定你至少運行過版本3.0?我相信在早期版本中語法是不允許的。 – eazar001 2013-02-22 07:38:08
@ eazar001是的,因爲我的代碼工作正常,沒有結束='' – prabhu 2013-02-22 10:43:19
出現在日食偏好設置爲v2.7,感謝您的幫助! – prabhu 2013-02-22 11:05:04