When you assign an object to a variable, Python copies the reference to the object.

In this case a and b refer to the same list.

If you want to copy the list (not just a reference to it), you can use the slice operator:

Making a slice of a creates a new list. in this case the slice contains all of the elements from the original list.

Another way to make a copy is the copy function from the copy module:

But is more idiomatic to use the slice operator.

from Thinking in Python

最新文章

  1. js 字符串操作函数
  2. Javascript学习笔记:3种检测变量类型的方法
  3. Spring scope
  4. php验证是否是中文
  5. HDU 4512 吉哥系列故事——完美队形(LCIS)
  6. Java 网络编程(转)
  7. 一个php类 Autoloader
  8. 从头开始编写一个Orchard网上商店模块(4) - 创建ProductPart
  9. Windows Live Writer 代码插件改造
  10. JAVA 实现发牌的 改进
  11. Hadoop-2.2.0中国文献——MapReduce 下一代 —配置单节点集群
  12. markown编辑器截图粘贴预览,并将图片传至七牛云
  13. IOS中UIScrollView的contentSize、contentOffset和contentInset属性
  14. javascript中的eval函数
  15. Python3下POST请求HTTPS链接
  16. 【原创】XAF CriteriaOperator 使用方式汇总
  17. Golang并发模型之Context详解
  18. JDK中的注解简单了解
  19. 谈谈 老罗和"锤子"
  20. 腾讯QQ的发展与未来

热门文章

  1. Unsupported major.minor version 51.0问题的解决
  2. linux下通过命令启动多个终端运行对应的命令和程序
  3. Java路径问题终于解决方式—可定位全部资源的相对路径寻址
  4. Android学习之——自己搭建Http框架(2)——框架扩展
  5. Install Rails on ubuntu 12.04 LTS
  6. Redis-4-链表结构
  7. URAL 1297 后缀数组+线段树
  8. 51nod 1065 最小正字段和 解决办法:set存前缀和,二分插入和二分查找
  9. PC比价软件
  10. SQL Server查询死锁,杀死进程解决死锁