Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung |
| gf_informatik:python_extras [2024-01-16 10:19] – [List Slicing] hof | gf_informatik:python_extras [2024-02-04 09:03] (aktuell) – [List Slicing] hof |
|---|
| ### 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: |
| <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 |