Python 什么';使用这些类有什么问题?

Python 什么';使用这些类有什么问题?,python,python-3.x,function,class,Python,Python 3.x,Function,Class,我试图调用函数login(),但正如您所看到的,它没有定义,这意味着我对类的理解完全错误-我试图理解它们的用法,正如您所看到的,我甚至都不是一个使用它们的初学者 谢谢你的帮助和提示 我想你是想写这门课: class Menu_choice(): def login(self): print("Login") def register(self): pring("Register") def __init__(self, choice):

我试图调用函数login(),但正如您所看到的,它没有定义,这意味着我对类的理解完全错误-我试图理解它们的用法,正如您所看到的,我甚至都不是一个使用它们的初学者


谢谢你的帮助和提示

我想你是想写这门课:

class Menu_choice():
    def login(self):
        print("Login")
    def register(self):
        pring("Register")
    def __init__(self, choice):
        self.choice = choice
        if self.choice == "LOGIN":
            self.login()
        if self.choice == "REGISTER":
            self.register()
但正如其他人所指出的,这类课程本身毫无意义。我想你想要这样的东西:

class Menu_choice():
    def __init__(self):
        pass
    def login(self):
        print("Login")
    def register(self):
        print("Register")
    def __call__(self, choice):
        self.choice = choice
        if self.choice == "LOGIN":
            self.login()
        if self.choice == "REGISTER":
            self.register()

choice = input("Would you like to login or register?: ").upper()
m = Menu_choice()
m(choice)

您可以将类设置为
m
,但也可以定义一个
\u调用
函数,当您调用实例时将执行该函数,如
m(choice)

请不要将代码/错误作为图像。使用代码格式(缩进4个空格)将它们写在问题中。这是
self.login()
,但这样使用类是没有意义的。请定义一些函数。请原谅我的无能,谢谢你的解决方案!