已经尝试过从几天内学习python,遇到了语法错误,但是在我正在学习的教程中似乎有效,下面是代码
def func(a):
for i in range(a,10):
print(i,end=' ')职能(2)
和错误
print(i,end=' ')
^SyntaxError:无效语法
发布于 2016-08-29 12:59:57
在Python 3中,这应该工作得很好,但是在Python 2中不能工作,因为它是一种不同的语法--这里的代码是为不同的Python版本修改的。
Python 3
def func(a):
for i in range(a,10):
print(i,end=' ')
>>> func(1)
>>> 1 2 3 4 5 6 7 8 9Python 2
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
https://stackoverflow.com/questions/15018875
复制相似问题