不明白这个“NameError: name 'self' is not defined”错误

morskiq123

我不断收到相同的错误消息:

回溯(最近一次通话):文件“”,第 1 行,在
my_wallet.checkBalance(self) NameError: name 'self' 未定义

balance = 0
def intro():
    global balance
    balance = int(input("How much would you like to start with? No more than 200£! ")
    if balance > 200:
        print("I said less than 200£!")
        intro()
class wallet:
    def __init__(self,money,broke):
        self.broke = False
        self.money = balance
    def checkBalance(self):
        self.money = balance
        print(balance)
    def noCash(self):
        if balance <= 0:
            print("You're done! No more £££!"
        self.broke = True
亚力克

从异常看来,您似乎试图将my_wallet.checkBalance传递self作为参数调用

尝试做my_wallet.checkBalance()而不是my_wallet.checkBalance(self)

self 参数自动传递给python中的类方法

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误“NameError: name 'self' is not defined”即使我声明了“self”

我不明白这个错误:“SequelizeEagerLoadingError”

不明白这个无效的参数错误

我不明白的错误

为什么我会收到“NameError: name 'self' is not defined”?

raise self._value NameError: name 'global_df' is not defined

我不明白为什么编译器会给我这个代码错误

不明白这个没有名为“ tkinter”的模块错误

我有这个错误:无法读取null的属性“值”,我不明白为什么

我不明白为什么我的代码中出现这个未定义的错误

我不明白为什么我会收到这个错误:[...] 有多个参数值 [...]

我是 Java 编程的新手,显然不明白我在这个项目中遇到的错误

不明白为什么我在使用 image_picker 时遇到这个错误

这是错误还是我不明白?

不明白我收到的错误?

不明白错误信息

TypeError: 'int' object is not subscriptable - 我已经研究了几个小时了,我不明白为什么它会吐出这个错误

我是PHP的新手,我不明白为什么会收到这个未定义的变量错误

如何解决错误 NameError: name 'SparkConf' is not defined in pycharm

我有一个错误:NameError: name 'GameDisplay' is not defined

你能建议如何解决这个问题吗?基本上我不明白这个错误来修复它

为什么我会收到此错误“NameError:name 'self' 未定义。”

我不明白我遇到的valgrind错误

我不明白的PostgreSQL语法错误

std :: make_shared给出我不明白的错误

我不明白错误的含义是什么

我不明白的 Python 代码或 CNN 架构功能的错误

我不明白的Flash as3错误1180

我不明白为什么会收到以下错误