简体   繁体   中英

Python print in terminal returning 'invalid syntax'

Im using the terminal on my mac to run some python and when i try to print a string i get an invalid syntax error.

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

I've tried it with single quotes and with and without parentheses but i keep getting that error, what is wrong.

Should be:

print('hi')

You have proper British quotes 'foo' . Those are the right symbols to use when writing human-readable texts, but Python wants actual single quotes ' .

Your editor probably has some kind of smart-quotes feature enabled, it is wise to turn this off when writing code (eg configure your editor to detect extensions like .py ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM