Python print in terminal returns "invalid syntax"

I am using terminal on my mac to run some python, and when I try to print a line, I get an invalid syntax error.

Michaels-MBP:~ mike$ python text.py
File "text.py", line 2
print(‘hi’)
      ^
SyntaxError: invalid syntax

      

I tried it with single quotes and with and without parentheses, but I keep getting this error which is not the case.

+3


source to share


1 answer


Should be:

print('hi')

      



You have the correct British quotes ‘foo’

. These are the correct characters to use when writing human-readable text, but Python wants single quotes '

.

Your editor may have some kind of smart quotes feature, it is advisable to disable this when writing code (for example, configure the editor to detect extensions such as .py

).

+4


source







All Articles