python - 语法错误:非 UTF-8?
问题描述
age = int(input("Please type your age:"))
if int(age) >= 18:
print("Sorry, you couldn't enter!")
else:
print("Congratulation, have a good time!")
SyntaxError: 第 1 行的文件 go to.py 中以 '\xa3' 开头的非 UTF-8 代码,但未声明编码;
为什么?
解决方案
您的代码包含几个 python 解释器无法识别的字符。它们看起来像普通(
的并且:
:
In [8]: ord('(')
Out[8]: 40
In [9]: ord('(')
Out[9]: 65288
In [10]: ord(':')
Out[10]: 58
In [11]: ord(':')
Out[11]: 65306
似乎您从某处复制了代码 - 只需手动将所有括号和冒号替换为有效字符
推荐阅读
- entity-framework-core - EF 核心请求无法唤醒 Azure Sql(无服务器 sku)数据库并超时
- laravel-blade - 如何在livewire中获取菜单活动元素的应用程序的当前url
- python - 无法使用 anaconda navigator 在我的 Windows10 系统上打开 jupyter notebook
- nestjs - NestJs 管道与过滤器
- python - ROS 中的持续时间计算和控制 - 此外,为什么即使在按下 Ctrl-C 后该脚本仍会继续运行?
- css - 如何从页面左右滑动模态窗口
- python - I am trying to resume training from a certain checkpoint (Tensorflow) because I'm using Colab and 12 hours aren't enough
- python - 了解 SQLAlchemy ForeignKey 关系查询结果
- flutter - Flutter灵活文本在列中溢出
- python - ImportError:无法从“plotly.express”导入名称“Constant”