python中的等于“=”

本文探讨了Python中列表赋值和复制的区别,通过示例说明了直接赋值导致的地址共享问题,并介绍了使用copy()方法来避免这一问题的方法。

注意python中“等于”的用法,列表的“=”和c语言中相同,是地址指针,源地址a的值变了,b也就变了。以前用python没注意到。可以用copy()取地址的值

  1. 常量

     a = 2
     b = a
     print(a, b)
     a = 4
     print(a, b)
    

2 2
4 2

  1. 列表

     a = [1, 2, 3]
     b = a
     print(a, b)
     a[0] = 44
     print(a, b)
    

[1, 2, 3] [1, 2, 3]
[44, 2, 3] [44, 2, 3]

  1. copy()

     a = [1, 2, 3]
     b = a.copy()
     print(a, b)
     a[0] = 44
     print(a, b)
    

[1, 2, 3] [1, 2, 3]
[44, 2, 3] [1, 2, 3]

ERROR: Ignored the following versions that require a different python version: 1.14.0 Requires-Python >=3.10; 1.14.0rc1 Requires-Python >=3.10; 1.14.0rc2 Requires-Python >=3.10; 1.14.1 Requires-Python > =3.10; 1.15.0 Requires-Python >=3.10; 1.15.0rc1 Requires-Python >=3.10; 1.15.0rc2 Requires-Python >=3.10; 1.15.1 Requires-Python >=3.10; 1.15.2 Requires-Python >=3.10; 1.15.3 Requires-Python >=3.10; 1.1 6.0 Requires-Python >=3.11; 1.16.0rc1 Requires-Python >=3.11; 1.16.0rc2 Requires-Python >=3.11; 1.16.1 Requires-Python >=3.11; 1.16.2 Requires-Python >=3.11; 1.3.1 Requires-Python >=3.10; 1.3.2 Requires -Python >=3.10; 1.3.3 Requires-Python >=3.11; 1.4.10rc0 Requires-Python >=3.10; 1.4.8 Requires-Python >=3.10; 1.4.9 Requires-Python >=3.10; 2.1.0 Requires-Python >=3.10; 2.1.1 Requires-Python >=3.10; 2. 1.2 Requires-Python >=3.10; 2.1.3 Requires-Python >=3.10; 2.2.0 Requires-Python >=3.10; 2.2.1 Requires-Python >=3.10; 2.2.2 Requires-Python >=3.10; 2.2.3 Requires-Python >=3.10; 2.2.4 Requires-Python >= 3.10; 2.2.5 Requires-Python >=3.10; 2.2.6 Requires-Python >=3.10; 2.3.0 Requires-Python >=3.11; 2.3.1 Requires-Python >=3.11; 2.3.2 Requires-Python >=3.11; 2.3.3 Requires-Python >=3.11; 3.10.0 Requires-Python >=3.10; 3.10.0rc1 Requires-Python >=3.10; 3.10.1 Requires-Python >=3.10; 3.10.3 Requires-Python >=3.10; 3.10.5 Requires-Python >=3.10; 3.10.6 Requires-Python >=3.10; 3.10.7 Requires-Python >=3.10 ERROR: Could not find a version that satisfies the requirement text-editor (from os-sys) (from versions: none) ERROR: No matching distribution found for text-editor 之前的报错,我应该使用Python3.11对吧
10-11
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值