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 = []不一样。