力扣简单题,用python列表模拟栈实现队列,答案有个地方不太理解,关于python的类和对象有什么好的教材吗

```
题目要实现的操作
使用栈实现队列的下列操作:

push(x) -- 将一个元素放入队列的尾部。
pop() -- 从队列首部移除元素。
peek() -- 返回队列首部的元素。
empty() -- 返回队列是否为空。

```###### 问题相关代码,请勿粘贴截图
class MyQueue:

def __init__(self):
    """
    in主要负责push,out主要负责pop
    """
    self.stack_in = []
    self.stack_out = []


def push(self, x: int) -> None:
    """
    有新元素进来,就往in里面push
    """
    self.stack_in.append(x)


def pop(self) -> int:
    """
    Removes the element from in front of queue and returns that element.
    """
    if self.empty():
        return None
    
    if self.stack_out:
        return self.stack_out.pop()
    else:
        for i in range(len(self.stack_in)):
            self.stack_out.append(self.stack_in.pop())
        return self.stack_out.pop()


def peek(self) -> int:
    """
    Get the front element.
    """
    ans = self.pop()    #就是这个地方,为什么是self.pop,而不是self.stack_out
    self.stack_out.append(ans)
    return ans


def empty(self) -> bool:
    """
    只要in或者out有元素,说明队列不为空
    """
    return not (self.stack_in or self.stack_out)
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果