a[:] = b 和 a = b[:] 之间的区别?(Python) [英] Difference between a[:] = b and a = b[:]? (Python)
本文介绍了a[:] = b 和 a = b[:] 之间的区别?(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被要求进行编码测试,但我不知道答案.有人有什么想法吗?
I was asked this for a coding test and didn't know the answer. Anyone have any ideas?
推荐答案
[:]
是切片操作符.
当它在左侧时,它会覆盖列表的内容而不创建新的引用.
When it's on the left side, it overwrites the contents of the list without creating a new reference.
当它位于右侧时,它会创建一个具有相同内容的列表副本.
When it's on the right side, it creates a copy of the list with the same contents.
这篇关于a[:] = b 和 a = b[:] 之间的区别?(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文