0
votes


I want to print this character "¥" in python 2.7. Here is my code:

test = "¥"
print(test)

I execute this code and I get this error message:

SyntaxError: Non-ASCII character '\xc2' in file main.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

How to print this character? Thanks in advance

1

1 Answers

0
votes

You need to specify the following line in the top of file:

# -*- coding: <encoding> -*-

Next time when you run this file Python will know what the encoding of that character is.

It will look like this, assuming you use utf-8.

# -*- coding: utf-8 -*-
test = "¥"
print(test)