绑定方法-Python [关闭]

问题描述 投票:1回答:1
class Iloilo():
     def Population(self):
        population = 946146
        return population


class Palawan():
    def Population(self):
        population = 1104585
        return population


Iloilo = Iloilo()
Palawan = Palawan()

print(Iloilo.Population)
print(Palawan.Population)

我正在尝试打印其值,但出现一条错误消息:bound method

我的问题是,如何比较两种方法的结果?

python python-3.x
1个回答
0
投票

您需要做:

ilolio_instance = Iloilo()
palawan_instance = Palawan()
print(ilolio_instance.Population()) 
print(palawan_instance.Population())

0
投票

使用下面的代码

class Iloilo():
    def Population(self):
        population = 946146
        return population

class Palawan():
    def Population(self):
        population = 1104585
        return population

a= Iloilo()
b=Palawan()
print(a.Population(),b.Population())
© www.soinside.com 2019 - 2024. All rights reserved.