How to display special characters in Python with print

后端 未结 5 944
迷失自我
迷失自我 2020-12-09 12:22

In a Python program that I am writing, I need to print the © (copyright) symbol. Is there an easy way to do this? Or is it not supported in Python? Here\'s an example.

5条回答
  •  攒了一身酷
    2020-12-09 12:53

    The copyright sign is a unicode character. If your terminal supports a character encoding (such as utf-8 or cp1252) that includes this character, then you can print it:

    This relies on Python detecting the terminal's character encoding:

    In [64]: print(u'\N{COPYRIGHT SIGN}')
    ©
    

    This uses an explicit encoding (which happens to work since my terminal is set to use the utf-8 character encoding):

    In [65]: print(u'\N{COPYRIGHT SIGN}'.encode('utf-8'))
    ©
    

提交回复
热议问题