I've got the following code that displays the degree symbol and it works fine with Python3 in PyCharm:
print(u'\u00b0'+ " F")
But when I move the code over to Python3 on my Pi I get the following error:
print(u'\u00b0'+ " F") ^ SyntaxError: invalid syntax
Does anyone have any idea on why this happens and how to fix it?
In Python versions 3.0 through 3.2, the u
prefix on a string literal was not allowed. Python 3.3 reintroduced it to aid in writing code that works in both Python 2 and Python 3 (see PEP 414).
I suspect your code is failing in one of the older versions of Python 3, and working on the other system in a newer version. In any version of Python 3, the u
is unnecessary. You can just write '\u00b0'+ " F"
or even '\u00b0 F'
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With