为什么一些python源代码这样写:a [:] = []?

时间:2018-09-07 10:40:27

标签: python

a [:] = []和a = []有什么区别?

我从asyncio的未来模块中看到了这种代码,这是代码:

def _schedule_callbacks(self):
    """Internal: Ask the event loop to call all callbacks.

    The callbacks are scheduled to be called as soon as possible. Also
    clears the callback list.
    """
    callbacks = self._callbacks[:]
    if not callbacks:
        return

    self._callbacks[:] = []
    for callback in callbacks:
        self._loop.call_soon(callback, self)

我不知道self._callbacks [:] = []运行时真正发生了什么,我认为这与self._callbacks = []不一样。

0 个答案:

没有答案