3

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.

1
  • In python, strings should be written either inside single quotes(') or in double quotes(") Commented May 8, 2015 at 7:48

1 Answer 1

4

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 (e.g. configure your editor to detect extensions like .py).

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

2 Comments

If you look closely, you should see that the opening and closing single quotes are different, suggesting that @PM2Ring is correct
Yes that’s right, those are British quotes, apostrophe was just the first thing that came to my mind.

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.