I get "SyntaxError: invalid syntax" for no reason (I think)

Question:

this is the code
print(f"{DataBase.Count()} Usersn")
and this is the error

    print(f"{DataBase.Count()} Usersn")
                                      ^
SyntaxError: invalid syntax

and i dont know how to fix it please help me

Asked By: seifahmed15

||

Answers:

You are trying to run Python 3 (in fact Python >= 3.6) in Python 2.7.

The Python 2.7 version of this code would be:

    print "{} Usersn".format(DataBase.Count())

But what you should really do is upgrade to Python 3. The method will vary depending on whether you are on Linux/Mac/Windows. Google "upgrade Python 2 to 3 [your operating system name here]".

Answered By: ljdyer

If you want to use fstring in python 2.7, you could use this lib: https://github.com/asottile-archive/future-fstrings

fstring is added after python 3.6.

Answered By: Allonsy Jia
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.