Zum Hauptinhalt springen
YouTube Security VideosTechquickie: How to Buy a VR Headset(02.10.2026 um 22:15 Uhr)
••
Videos & KonferenzenTechquickie: How to Buy a VR Headset(02.10.2026 um 22:15 Uhr)
•
Sicherheitslücken (CVE)Cross-Site Scripting in Joomla Toolbar Link Layout(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Cross-Site Scripting in Joomla HTML Mail Templates(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Cross-Site Scripting in Joomla HTMLHelper Link and Iframe Methods(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Cross-Site Scripting in Joomla Media Field Audio/Video Layouts(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Improper Access Control in Joomla Workflow Stage Batch Change(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Information Disclosure in Joomla Tagged Items Listings(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Incorrect Access Control in Joomla webservice edit tasks(02.10.2026 um 18:34 Uhr)
•
YouTube Security VideosTechquickie: How to Buy a VR Headset(02.10.2026 um 22:15 Uhr)
••
Videos & KonferenzenTechquickie: How to Buy a VR Headset(02.10.2026 um 22:15 Uhr)
•
Sicherheitslücken (CVE)Cross-Site Scripting in Joomla Toolbar Link Layout(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Cross-Site Scripting in Joomla HTML Mail Templates(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Cross-Site Scripting in Joomla HTMLHelper Link and Iframe Methods(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Cross-Site Scripting in Joomla Media Field Audio/Video Layouts(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Improper Access Control in Joomla Workflow Stage Batch Change(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Information Disclosure in Joomla Tagged Items Listings(02.10.2026 um 18:34 Uhr)
•
Sicherheitslücken (CVE)Incorrect Access Control in Joomla webservice edit tasks(02.10.2026 um 18:34 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Shallow Copy & Deep Copy in Python

Buy Me a Coffee☕ *My post explains variable assignment in Python. Normal Copy: *Memos: The reference of a list is stored in a variable. v1 and v2 have the same …

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

Buy Me a Coffee☕



*My post explains variable assignment in Python.






Normal Copy:



*Memos:




  • The reference of a list is stored in a variable.


  • v1 and v2 have the same references of the same shallow list.


  • v1 and v2 have the same references of the same deep list.




     #### Shallow list ####
# ↓↓↓↓↓↓↓↓↓↓↓ ↓
v1 = ['a', 'b', ['c', 'd']] # Equivalent
v2 = v1 # ↑↑↑↑↑↑↑↑↑↑ # v1 = v2 = ['a', 'b', ['c', 'd']]
# Deep list

print(v1, v2) # ['a', 'b', ['c', 'd']] ['a', 'b', ['c', 'd']]

v2[1] = 'B'
v2[2][0] = 'C'
# ↓↓↓ ↓↓↓ ↓↓↓ ↓↓↓
print(v1, v2) # ['a', 'B', ['C', 'd']] ['a', 'B', ['C', 'd']]









Shallow Copy



*Memos:





  • copy() can be used for shallow copy.


  • v1 and v2 have the different references of the different shallow lists.


  • v1 and v2 have the same references of the same deep list.




v1 = ['a', 'b', ['c', 'd']]
v2 = v1.copy()

print(v1, v2) # ['a', 'b', ['c', 'd']] ['a', 'b', ['c', 'd']]

v2[1] = 'B'
v2[2][0] = 'C'
# ↓↓↓ ↓↓↓ ↓↓↓
print(v1, v2) # ['a', 'b', ['C', 'd']] ['a', 'B', ['C', 'd']]






*The below with copy() is equivalent to the above.




import copy

v1 = ['a', 'b', ['c', 'd']]
v2 = copy.copy(v1)

print(v1, v2) # ['a', 'b', ['c', 'd']] ['a', 'b', ['c', 'd']]

v2[1] = 'B'
v2[2][0] = 'C'
# ↓↓↓ ↓↓↓ ↓↓↓
print(v1, v2) # ['a', 'b', ['C', 'd']] ['a', 'B', ['C', 'd']]






*The below with list() is equivalent to the above.




v1 = ['a', 'b', ['c', 'd']]
v2 = list(v1)

print(v1, v2) # ['a', 'b', ['c', 'd']] ['a', 'b', ['c', 'd']]

v2[1] = 'B'
v2[2][0] = 'C'
# ↓↓↓ ↓↓↓ ↓↓↓
print(v1, v2) # ['a', 'b', ['C', 'd']] ['a', 'B', ['C', 'd']]









Deep Copy



*Memos:





  • deepcopy() can be used for deep copy.


  • v1 and v2 have the different references of the different shallow lists.


  • v1 and v2 have the different references of the different deep lists.




import copy

v1 = ['a', 'b', ['c', 'd']]
v2 = copy.deepcopy(v1)

print(v1, v2) # ['a', 'b', ['c', 'd']] ['a', 'b', ['c', 'd']]

v2[1] = 'B'
v2[2][0] = 'C'
# ↓↓↓ ↓↓↓
print(v1, v2) # ['a', 'b', ['c', 'd']] ['a', 'B', ['C', 'd']]


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Shallow Copy & Deep Copy in Python

Thematisch verwandte Begriffe: Shallow, Copy, Deep, Python · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag