Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

List in Python (2)

Buy Me a Coffee☕ *Memos: My post explains how to create a list and access and change a list by indexing. My post explains the useful functions for a list (1). My post explains the useful functions for a list (2). My post explains v…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Buy Me a Coffee



*Memos:





  • My post explains how to create a list and access and change a list by indexing.


  • My post explains the useful functions for a list (1).


  • My post explains the useful functions for a list (2).


  • My post explains variable assignment.


  • My post explains shallow copy and deep copy.



You can access and change a list by slicing as shown below:

*Memos:




  • A list is mutable.

  • Slicing can be done with one or more [start:end:step].


  • start(Optional-Default:The index of the 1st element).


  • end(Optional-Default:The index of the last element - 1).


  • step(Optional-Default:1). *step mustn't be zero.

  • The [] with at least one : is slicing.

  • Slicing does shallow copy.




v1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] # 1D list

print(v1[:])
print(v1[::])
# ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']

print(v1[::2])
# ['a', 'c', 'e', 'g']

print(v1[::-2])
# ['h', 'f', 'd', 'b']

print(v1[2:])
print(v1[-6:])
print(v1[2::])
print(v1[-6::])
# ['c', 'd', 'e', 'f', 'g', 'h']

print(v1[2::2])
print(v1[-6::2])
# ['c', 'e', 'g']

print(v1[2::-2])
print(v1[-6::-2])
# ['c', 'a']

print(v1[:6])
print(v1[:-2])
print(v1[:6:])
print(v1[:-2:])
# ['a', 'b', 'c', 'd', 'e', 'f']

print(v1[:6:2])
print(v1[:-2:2])
# ['a', 'c', 'e']

print(v1[:6:-2])
print(v1[:-2:-2])
# ['h']

print(v1[2:6])
print(v1[-6:-2])
print(v1[2:6:])
print(v1[-6:-2:])
# ['c', 'd', 'e', 'f']

print(v1[2:6:2])
print(v1[-6:-2:2])
# ['c', 'e']

print(v1[2:6:-2])
print(v1[-6:-2:-2])
# []

v2 = v1[:]
v2[2:6] = [0, 1, 2, 3, 4, 5]
print(v2) # ['a', 'b', 0, 1, 2, 3, 4, 5, 'g', 'h']

v2 = v1[:]
v2[2:6] = [[0, 1, 2, 3, 4, 5]]
print(v2) # ['a', 'b', [0, 1, 2, 3, 4, 5], 'g', 'h']

v2 = v1[:]
v2[2:6:2] = [0, 1]
print(v2) # ['a', 'b', 'X', 'd', 'Y', 'f', 'g', 'h']

v2 = v1[:]
v2[2:6:2] = [[0, 1, 2], [3, 4, 5]]
print(v2) # ['a', 'b', [0, 1, 2], 'd', [3, 4, 5], 'f', 'g', 'h']









v1 = [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h']] # 2D list

print(v1[:])
print(v1[::])
print(v1[:][:])
print(v1[::][::])
# [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h']]

print(v1[0][:])
print(v1[0][::])
print(v1[-2][:])
print(v1[-2][::])
# ['a', 'b', 'c', 'd']

print(v1[0][::2])
print(v1[-2][::2])
# ['a', 'c']

print(v1[0][::-2])
print(v1[-2][::-2])
# ['d', 'b']

print(v1[1][:])
print(v1[1][::])
print(v1[-1][:])
print(v1[-1][::])
# ['e', 'f', 'g', 'h']

print(v1[1][::2])
print(v1[-1][::2])
# ['e', 'g']

print(v1[1][::-2])
print(v1[-1][::-2])
# ['h', 'f']

v2 = v1[:]
v2[0][1:3] = [0, 1, 2, 3]
v2[1][::2] = [0, 1]
print(v2) # [['a', 0, 1, 2, 3, 'd'], [0, 'f', 1, 'h']]

v2 = v1[:]
v2[0][1:3] = [[0, 1, 2, 3]]
v2[1][::2] = [[0, 1, 2, 3], [0, 1, 2, 3]]
print(v2) # [['a', [0, 1, 2, 3], 'd'], [[0, 1, 2, 3], 'f', [0, 1, 2, 3], 'h']]









v1 = [[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]] # 3D list

print(v1[:])
print(v1[::])
print(v1[:][:])
print(v1[::][::])
print(v1[:][:][:])
print(v1[::][::][::])
# [[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]

print(v1[0][:])
print(v1[0][::])
print(v1[-2][:])
print(v1[-2][::])
# [['a', 'b'], ['c', 'd']]

print(v1[1][:])
print(v1[1][::])
print(v1[-1][:])
print(v1[-1][::])
# [['e', 'f'], ['g', 'h']]

print(v1[0][0][:])
print(v1[0][0][::])
print(v1[-2][-2][:])
print(v1[-2][-2][::])
# ['a', 'b']

print(v1[0][0][::2])
print(v1[-2][-2][::2])
# ['a']

print(v1[0][0][::-2])
print(v1[-2][-2][::-2])
# ['b']

print(v1[0][1][:])
print(v1[0][1][::])
print(v1[-2][-1][:])
print(v1[-2][-1][::])
# ['c', 'd']

print(v1[0][1][::2])
print(v1[-2][-1][::2])
# ['c']

print(v1[0][1][::-2])
print(v1[-2][-1][::-2])
# ['d']

print(v1[1][0][:])
print(v1[1][0][::])
print(v1[-1][-2][:])
print(v1[-1][-2][::])
# ['e', 'f']

print(v1[1][0][::2])
print(v1[-1][-2][::2])
# ['e']

print(v1[1][0][::-2])
print(v1[-1][-2][::-2])
# ['f']

print(v1[1][1][:])
print(v1[1][1][::])
print(v1[-1][-1][:])
print(v1[-1][-1][::])
# ['g', 'h']

print(v1[1][1][::2])
print(v1[-1][-1][::2])
# ['g']

print(v1[1][1][::-2])
print(v1[-1][-1][::-2])
# ['h']

v2 = v1[:]
v2[0][1:] = [0, 1, 2, 3]
v2[1][0][0:] = [0, 1, 2, 3]
v2[1][1][::2] = [[0, 1, 2, 3]]
print(v2) # [[['a', 'b'], 0, 1, 2, 3], [[0, 1, 2, 3], [[0, 1, 2, 3], 'h']]]






The reference of a list is stored in a variable as shown below:



*Memos:




  • The variables v1 and v2 and have the same references of the same list, that's why changing the list content of v2 also changes the other list content of v1.


  • is keyword can check if v1 and v2 have the same references.

  • Again, slicing does shallow copy.


  • copy() can also do shallow copy. *There are no arguments.




v1 = ['a', 'b', 'c', 'd']

v2 = v1 # v2 has the same reference of the same list as v1.

v2[2] = 'X' # Changes the same list content by the same reference as v1.
# ↓↓↓
print(v1) # ['a', 'b', 'X', 'd']
print(v2) # ['a', 'b', 'X', 'd']
# ↑↑↑
print(v1 is v2) # True

v2 = v1[:] # v2 has the different reference of the different list
v2 = v1.copy() # from v1.

v2[2] = 'Y' # Changes a different list content by the different reference
# from v1.
# ↓↓↓
print(v1) # ['a', 'b', 'X', 'd']
print(v2) # ['a', 'b', 'Y', 'd']
# ↑↑↑
print(v1 is v2) # False


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten List in Python (2)

Thematisch verwandte Begriffe: List, 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 ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-18163 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
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
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick