简体   繁体   中英

How to use utf-8 characters in a comment in Python source code?

I think that I understand how to create a string that encodes a UTF-8 characters. But, I'm trying to do something a bit different. Is it possible to use UTF-8 characters in a comment in Python source code? And, are there any Python IDEs or source code editors that will recognize the UTF-8 sequences and display the characters correctly?

VS2015 can certainly use UTF-8 files as source code, but it will try to use the default ANSI encoding if you just type a degree sign in source code and your ANSI encoding encodes the character (varies by localized Windows version). Use a tool like Notepad++ to save the source as UTF-8 and VS2015 still detects and reads the file correctly.

The below file was created in Notepad++ and saved as Encoding, UTF-8:

print('\u00b0')  # This is a °.
print('°°°°')    # So are these.

It displays correctly loaded in VS2015 as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM