python折磨
1.写方法没有self
class Stack: """ @param: x: An integer @return: nothing """ def __init__(self): zhai = [] def push(self, x): # write your code here zhai.append(x) """ @return: nothing """ def pop(self): # write your code here zhai.pop(0) """ @return: An integer """ def top(self): # write your code here return(zhai[-1]) """ @return: True if the stack is empty """ def isEmpty(self): # write your code here if zhai==[]: return True else: return False
蠢的一批,应该这样写
class Stack: """ @param: x: An integer @return: nothing """ def __init__(self): self.zhai = [] def push(self, x): # write your code here self.zhai.append(x) """ @return: nothing """ def pop(self): # write your code here self.zhai.pop(0) """ @return: An integer """ def top(self): # write your code here return(self.zhai[-1]) """ @return: True if the stack is empty """ def isEmpty(self): # write your code here if self.zhai==[]: return True else: return False