代码标红却还能运行,不知道问题在哪里

img


show那里标红了,却可以运行,代码没有发现其他什么问题

跟编辑器有关,标红是语法检测,不是红叉就没问题。

如果是类的实例方法 缺失参数self 如果是类方法的话 要加@classmethod

楼上正解

class Student:
    __name = "ddd"
    __age = 12
    
    @staticmethod
    def show():
        print(Student.__age,Student.__name)

Student.show()