2

Just a sample question. Is it possible to show the symbol ± in Python? I just tried to use the Extended ASCII Codes char(241), but it didn't work.

The simple code:

b = chr(241) #The Extended ASCII Codes for 241 is this symbol "±". print(b) 

The result showed UnicodeEncodeError: 'ascii' codec can't encode character '\x80' in position 0: ordinal not in range(128)

Can someone help? Thanks

I just want to test if I could show the Extended ASCII Codes in Python. There is no complicated code.

Here is the code and result: enter image description here

11
  • @abccd Got it. I just thought, there are actually only one assignment and one print statement in the code. It's not very necessary to write the code. Th e screenshot is more clear. So could you please tell me how to show this symbol correctly? Thanks. Commented Jun 10, 2017 at 6:52
  • 2
    What's wrong with print('±')? Commented Jun 10, 2017 at 6:55
  • 2
    Possible duplicate of "UnicodeEncodeError: 'ascii' codec can't encode character" Commented Jun 10, 2017 at 7:00
  • 1
    I'm also running 3.6.1 and it works fine for me. Check the Sublime documentation for console settings, or run your program from a command-line which supports the correct character set. Commented Jun 10, 2017 at 7:18
  • 1
    @cdarke Got it. It works with the command-line. Commented Jun 10, 2017 at 7:21

1 Answer 1

1

Summarizing the comments, any of the following alternatives can be applied

print('±') # Provided your terminal supports Unicode print('\xB1') # For all cases. 
Sign up to request clarification or add additional context in comments.

1 Comment

print('\xB1') # For all cases

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.