python新建类时突然出现错误:error while code parsing”

做了个简单测试

class Cat:
    def eat(self):
        print("小猫爱吃鱼")
    def drink(self):
        print("小猫要喝水")


tom = Cat()
tom.drink()
tom.eat()

结果出现以下错误:
error while code parsing: Wrong or no encoding specified for d:\Code Source\VSCODE\python\test.py.

这是为什么?

指定编码格式试试

# -*- coding: utf-8 -*-

十有八九是你用的IDE的问题,建议尝试更换IDE,或者研究下IDE的配置。
或者通过终端来执行代码 python3 d:\Code Source\VSCODE\python\test.py

定义函数后的print有后置4个字符吗?