0

I started learning python the other day. I have a fibonacci function that I copied from python docs. It gives a syntax error on the print statement with the end=''

I rewrote all the code manually and still i get the error

def fibonacci2(n):
    a, b = 0, 1
    while b < n:
        print(b, end=' ')
        a, b = b, a+b
    print()    

It says syntax error while detecting tuple

Thanks in advance

edit: i am sorry that i forgot to write, i am using python 3.

1
  • 8
    Put from __future__ import print_function atop the file (or upgrade to Python 3). Commented Mar 12, 2014 at 11:46

2 Answers 2

1

In Python 3.x you can write print(b, end=' '), you cant write print(b, end=' ') in Python 2.x . Because in Python 3.x print is function and in Python 2.x print is just statement.

If you want to use end='' in print statement in Python 2.x you should use from __future__ import print_function

Sign up to request clarification or add additional context in comments.

Comments

0

it's important to remember that in python < V3.x print is not a function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.