无法调用/调用Python方法

Tre*_*ent 0 python class

无法使我的类变量正常工作,

class World:
  def __init__(self, size):
    self.size = size
    self.grid = []
    for i in range(0,size):
        self.grid.append([])
        for j in range(0,size):
            self.grid[i].append(0)
  def Display(self):
    for row in self.grid:
        print row

TheWorld = World(int(raw_input("Input world size(integer): ")))
TheWorld.Display
Run Code Online (Sandbox Code Playgroud)

问题是,显示功能没有做任何事情,我认为它不是以某种方式正确引用self.grid.我输入的世界大小为0,10,100,没有什么区别.有任何想法吗 ??谢谢

Ava*_*ris 8

您没有调用该函数,您只是引用函数对象.尝试:

TheWorld.Display()
Run Code Online (Sandbox Code Playgroud)