Python3|解决Python代码编码问题 SyntaxError: Non-UTF-8 code starting with '\xc1'

【Python3|解决Python代码编码问题 SyntaxError: Non-UTF-8 code starting with '\xc1'】学习编写Py程序时突然报错:

SyntaxError: Non-UTF-8 code starting with '\xbb' in file C:\Users\v\Desktop\Test.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Python3|解决Python代码编码问题 SyntaxError: Non-UTF-8 code starting with '\xc1'
文章图片

由于python内部使用的是unicode编码,而外部却要面对千奇百怪的各种编码,因此很容易导致编码问题
解决方法:在代码顶部加入
# -*- coding: gbk -*-

借鉴文章:
https://blog.csdn.net/xz1308579340/article/details/70242453
官方解决:
https://www.python.org/dev/peps/pep-0263/

    推荐阅读