惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cisco Blogs
Schneier on Security
Schneier on Security
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Scott Helme
Scott Helme
Webroot Blog
Webroot Blog
Project Zero
Project Zero
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
Hacker News: Ask HN
Hacker News: Ask HN
PCI Perspectives
PCI Perspectives
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News | PayPal Newsroom
Help Net Security
Help Net Security
The Hacker News
The Hacker News
H
Heimdal Security Blog
O
OpenAI News
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 叶小钗
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security Affairs
P
Proofpoint News Feed
S
Secure Thoughts
腾讯CDC
Google DeepMind News
Google DeepMind News
量子位
罗磊的独立博客

博客园 - emanlee

mysql 在新电脑上导入,出现错误:ERROR at line 4019: Unknown command '\''. - emanlee 安装 yarn npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本。 - emanlee VS code, 最近打开过哪些项目或文件夹,把这些备份下来,到另外一台电脑上恢复 傲梅分区助手 【好用】 ubuntu 可以使用Windows远程桌面连接吗?【可以】 把xshell的全部连接和密码,从一台Windows 10电脑,迁移到Windows11电脑。 Windows 远程桌面(mstsc)完整迁移方案(含历史连接记录、RDP 配置、保存的账号密码)【可行】 Endnote,如何能完整迁移库和模版 ubuntu 安装 locate “华为杯”第八届中国研究生人工智能创新大赛 当数据量很大时,执行 mysql> source filename.sql 很慢,有什么办法更快 pip install django-ranged-response==0.2.0 部署Vue+Django 04c,mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory Ubuntu Server 24.04 安装 MySQL, ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory ubuntu server 24.04: 如何设置默认采用 Xorg 方式登录 Ubuntu Server 24.04 设置锁屏时间 Ubuntu Server 启动过程中,比较慢 Job systemd-networkd-wait-online.service/start running Ubuntu Server 24.04 启用root用户 Ubuntu snap install 安装todesk是否必须检查 CPU 是否支持 AVX / AVX2 命令 Ubuntu Server 24.04下解决SunloginClient 向日葵依赖libgconf-2-4安装问题 Ubuntu Server 24.04 安装图形界面 ubuntu server 24.04 安装 中文输入法 Ubuntu Server 24.04 安装浏览器firefox Ubuntu Server 24.04 安装todesk【先联网,CPU必须支持 AVX / AVX2 】 Ubuntu Server 24.04 安装中文,汉字 大驼峰命名法 python 容易理解类和对象的例子 django+mysql: 如何添加一个新的超级用户?
Python赋值,什么时候传引用?
emanlee · 2026-04-26 · via 博客园 - emanlee

Python 里所有赋值,全都是「传引用」(地址引用),没有传统意义上的拷贝赋值。

区别只在:不可变对象看上去像值传递,可变对象明显是引用共享。

1. 先分两类对象

不可变对象(值不会改)

int、float、str、bool、tuple

可变对象(内容能原地改)

list、dict、set、自定义对象

2. 赋值本质(永远一样) 

不是把列表复制一份给 b

而是:a 和 b 指向同一个内存地址的同一个对象

👉 这就是传引用

3. 什么时候能明显看出「传引用」

只要是可变对象赋值、传参、函数返回,都是共享引用: 

lst1 = [1,2]
lst2 = lst1   # 引用传递,指向同一个列表
lst2.append(3)

print(lst1)  # [1,2,3]  跟着变了! 

原因:lst1、lst2 是同一个内存地址

4. 为什么不可变对象好像不是传引用? 

a = 10
b = a
b = 20
print(a)  # 10 没变

不是没传引用,而是:

不可变对象不能原地修改,重新赋值只是让 b 指向了新地址,原来的 a 不受影响。

5. 函数传参也是一样规则

  • 可变对象:函数内修改会影响外部(引用共享)
  • 不可变对象:函数内重新赋值不影响外部
def func(x):
    x.append(99)

lst = [1,2]
func(lst)
print(lst)  # [1,2,99]  外部被改了,就是引用传递

6. 快速记忆口诀

  1. Python 赋值全是引用传递,无值传递
  2. list/dict/set/ 自定义类:赋值、传参都共享地址,改一个全变
  3. int/str/tuple:看似不影响,只因不可变,重新赋值就换地址
  4. 想断开引用、独立修改:用 .copy()、切片 [:]deepcopy