Copying lists
2024-08-31 08:07:19
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
最新文章
- js 字符串操作函数
- Javascript学习笔记:3种检测变量类型的方法
- Spring scope
- php验证是否是中文
- HDU 4512 吉哥系列故事——完美队形(LCIS)
- Java 网络编程(转)
- 一个php类 Autoloader
- 从头开始编写一个Orchard网上商店模块(4) - 创建ProductPart
- Windows Live Writer 代码插件改造
- JAVA 实现发牌的 改进
- Hadoop-2.2.0中国文献——MapReduce 下一代 —配置单节点集群
- markown编辑器截图粘贴预览,并将图片传至七牛云
- IOS中UIScrollView的contentSize、contentOffset和contentInset属性
- javascript中的eval函数
- Python3下POST请求HTTPS链接
- 【原创】XAF CriteriaOperator 使用方式汇总
- Golang并发模型之Context详解
- JDK中的注解简单了解
- 谈谈 老罗和&;quot;锤子&;quot;
- 腾讯QQ的发展与未来
热门文章
- Unsupported major.minor version 51.0问题的解决
- linux下通过命令启动多个终端运行对应的命令和程序
- Java路径问题终于解决方式—可定位全部资源的相对路径寻址
- Android学习之——自己搭建Http框架(2)——框架扩展
- Install Rails on ubuntu 12.04 LTS
- Redis-4-链表结构
- URAL 1297 后缀数组+线段树
- 51nod 1065 最小正字段和 解决办法:set存前缀和,二分插入和二分查找
- PC比价软件
- SQL Server查询死锁,杀死进程解决死锁