/ / end = '' erro de sintaxe python - python-3.x

end = '' erro de sintaxe python - python-3.x

Estive tentando aprender python de alguns dias, encontrei um erro de sintaxe mas parece funcionar no tutorial que estou aprendendo, aqui está o código

def func(a):
for i in range(a,10):
print(i,end=" ")

func (2)

E o erro

print(i,end=" ")
^

SyntaxError: sintaxe inválida

Respostas:

2 para resposta № 1

No Python 3, isso deve funcionar quase perfeitamente, no entanto, isso não funcionará no Python 2, pois é uma sintaxe diferente, aqui está o código modificado para funcionar em diferentes versões do Python

def func(a):
for i in range(a,10):
print(i,end=" ")
>>> func(1)
>>> 1 2 3 4 5 6 7 8 9

Python 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

Detalhe adicional

https://docs.python.org/3/whatsnew/3.0.html#common-stumbling-blocks