Python printing special Characters
Question:
In Python how do I print special characters such as √, ∞, ²,³, ≤, ≥, ±, ≠
When I try printing this to the console I the get this error:
print("√")
SyntaxError: Non-ASCII character 'xe2' in file /Users/williamfiset/Desktop/MathAid - Python/test.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
How do I get around this?
Answers:
Running this code results into the same SyntaxError
you’ve provided:
chars = ["√", "∞", "²","³", "≤", "≥", "±", "≠"]
for c in chars:
print(c)
But if I add # -*- coding: utf-8 -*-
at the top of the script:
# -*- coding: utf-8 -*-
chars = ["√", "∞", "²","³", "≤", "≥", "±", "≠"]
for c in chars:
print(c)
it will print:
√
∞
²
³
≤
≥
±
≠
Also, see SyntaxError of Non-ASCII character.
Hope that helps.
In Python how do I print special characters such as √, ∞, ²,³, ≤, ≥, ±, ≠
When I try printing this to the console I the get this error:
print("√")
SyntaxError: Non-ASCII character 'xe2' in file /Users/williamfiset/Desktop/MathAid - Python/test.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
How do I get around this?
Running this code results into the same SyntaxError
you’ve provided:
chars = ["√", "∞", "²","³", "≤", "≥", "±", "≠"]
for c in chars:
print(c)
But if I add # -*- coding: utf-8 -*-
at the top of the script:
# -*- coding: utf-8 -*-
chars = ["√", "∞", "²","³", "≤", "≥", "±", "≠"]
for c in chars:
print(c)
it will print:
√
∞
²
³
≤
≥
±
≠
Also, see SyntaxError of Non-ASCII character.
Hope that helps.