list.append() 存在的一些问题解释 copy?


```python
>>> a = [['a']]
>>> a.append(1)
>>> id(1)
94887599014656
>>> id(a[1])
94887599014656
>>>
>>> list = [1,12,'a']
>>> a.append(list)
>>> a
[['a'], 1, [1, 12, 'a']]
>>> id(a) == id(list)
False
>>> id(a[2]) == id(list)
True
>>> list.append(20)
>>> list
[1, 12, 'a', 20]
>>> a
[['a'], 1, [1, 12, 'a', 20]]
>>>
>>>
>>> a.append(list[:])
>>> a
[['a'], 1, [1, 12, 'a', 20], [1, 12, 'a', 20]]
>>> list.append(30)
>>> list
[1, 12, 'a', 20, 30]
>>> a
[['a'], 1, [1, 12, 'a', 20, 30], [1, 12, 'a', 20]]
>>> id(list)
140402674396368
>>> id(a[3])
140402673548016
>>>

注意list.append(obj),添加的是对象的引用 看以上代码的id()即可理解其添加都指向同一地址,在最后list[:]相当于切片 创建了一个新的对象传入,如a不会随之改变

python·根据内存地址获取对应内容
利用ctype
```python
>>> import ctypes
>>>
>>> get_value = ctypes.cast(140402673548016, ctypes.py_object).value
>>> get_value
[1, 12, 'a', 20]
>>>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Notepad++ v8 new features, enhancements & bug-fixes: 1. Add Dark Mode. 2. ARM64 build is available. 3. One button to build them all - build Notepad++ with Scintilla static lib and Boost RegExpr headers. 4. Add new Fluent UI icons for toolbar. 5. Add new feature "Distraction Free Mode" (Menu "View->Distraction Free Mode"). 6. Add new API NPPM_ADDTOOLBARICON_FORDARKMODE for dark mode. 7. Add 1 click action (SHIFT-click) on close button to close all tabs in dockable panel. 8. Add ability of changing select text foreground color (optional). 9. Allow Replace to stop after replacement (optional). 10. Fix append extension feature not working in save dialog. 11. Add ability to reverse line order. 12. Add ability to style only current instance of text. 13. Fix duplicated entries in Auto-Completion pop-up window. 14. Fix Python Function List not showing functions in some circumstance. 15. Enhance Folder as Workspace performance while adding/removing files in bulk. 16. Add Ada, Fortran, Fortran77 & Haskell in function lists. 17. Improve performance of "Open all" command in Search results. 18. Add "Copy Pathnames" command to Search results context menu. 19. Catch regex search exceptions and show exception message. 20. Add MarkAll Preference settings for case and word. 21. Fix regression: Handle "Default Directory" setting correctly in Open/Save File Dialog. 22. Fix a special character in UTF16 file crash issue 23. Add "Append extension" checkbox to Save As dialog. 24. Fix Copy command in Search result is available as there's no selection. 25. Add padding ability in the edit zone. 26. Make new tab name translatable. 27. Improve character case handling in RegEx. 28. Fix dragged out UDL file is not applied to UDL in the new instance. 29. Add command line parameter for adding specified string to app title bar. 30. Fix Auto-Completion ignoring case issue. 31. Fix "Match Whole Word" option being enabled in RegEx Search. 32. Fix sort with column key selection that appears af

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值