相关疑难解决方法(0)

调用函数的目的没有括号python

考虑以下:

class objectTest():

    def __init__(self,a):

        self.value = a

    def get_value(self):

        return self.value


class execute():

    def __init__(self):

        a = objectTest(1)
        b = objectTest(1)

        print(a == b)
        print(a.get_value() == b.get_value)
        print(a.get_value() == b.get_value())
        print(a.get_value == b.get_value)


if __name__ == '__main__':

    execute = execute();
Run Code Online (Sandbox Code Playgroud)

此代码返回

>>>
False
False
True 
False
Run Code Online (Sandbox Code Playgroud)

鉴于get_value是一个函数,我希望执行停止并返回错误,但事实并非如此.有人可以解释为什么python解释器允许这种语法而不是引发属性错误,这在我的情况下会节省我宝贵的时间.

python python-3.x

18
推荐指数
4
解决办法
2万
查看次数

标签 统计

python ×1

python-3.x ×1