Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
gf_informatik:python_extras [2024-01-16 10:19] – [List Slicing] hofgf_informatik:python_extras [2024-02-04 09:03] (aktuell) – [List Slicing] hof
Zeile 18: Zeile 18:
 ### List Slicing ### List Slicing
  
-Die `for`-Schleife ist ja viel kompakter und weniger fehleranfällig, als die `while?-Schleife - aber dafür auch weniger flexibel. Ist "jedes zweite Element" mit `for` möglich? Lies auf [[https://stackoverflow.com/questions/509211/how-slicing-in-python-works|Stackoverflow]] diese Antwort über Slicing!+Die `for`-Schleife ist ja viel kompakter und weniger fehleranfällig, als die `while`-Schleife - aber dafür auch weniger flexibel. Ist "jedes zweite Element" mit `for` möglich? Lies auf [[https://stackoverflow.com/questions/509211/how-slicing-in-python-works|Stackoverflow]] diese Antwort über Slicing!
  
 Kurz: Kurz:
Zeile 24: Zeile 24:
 <code python> <code python>
 a[start:stop]  # items start through stop-1 a[start:stop]  # items start through stop-1
-a[start:     # items start through the rest of the array+a[start:     # items start through the rest of the list
 a[:stop]       # items from the beginning through stop-1 a[:stop]       # items from the beginning through stop-1
-a[:]           # a copy of the whole array+a[:]           # a copy of the whole list
  
 a[start:stop:step] # start through not past stop, by step a[start:stop:step] # start through not past stop, by step
  • gf_informatik/python_extras.1705400373.txt.gz
  • Zuletzt geändert: 2024-01-16 10:19
  • von hof