14. Lektion: Variablen vielfalt.extend()
Zuweisungsvielfalt
Python ermöglicht es mehreren Variablen gleichzeitig Werte zuzuweisen.
- Mehrfach Zuweisung eines Wertes:
>>> a = b = c = 42
>>> print(a, b, c)
42 42 42
>>>
- Mehrfachzuweisung verschiedener Werte:
>>> a, b, c = 1, 2, 3
>>> print(a, b, c)
1 2 3
>>>
- Mehrfachzuweisung aus einer Liste:
>>> a, b, c = [10, 20, 30]
>>> print(a, b, c)
10 20 30
>>> z = [1, 2, 3]
>>> a, b, c = z
>>> print(a, b, c)
1 2 3
>>>
- Mehrfachzuweisung aus einer Liste mit mehr Werten:
>>> z = [1, 2, 3, 4, 5]
>>> a, b, c = z
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 3)
>>> a, b, *c = z
>>> print(a, b, c)
1 2 [3, 4, 5]
>>>
>>> z = [1, 2, 3]
>>> a, b, *c = z
>>> print(a, b, c)
1 2 [3]
>>>
Inhalte tauschen
>>> x, y = 1, 2 >>> print(x, y) 1 2 >>> y, x = x, y >>> print(x, y) 2 1 >>>
- Listen
- Slicing
- Konstanten
- copy deep und flach
- https://www.heise.de/ratgeber/Phyton-Welche-Auflistungstypen-es-gibt-und-wie-sie-verwendet-werden-9216638.html?seite=all
- https://levelup.gitconnected.com/30-phyton-concepts-i-wish-i-knew-way-earlier-3add72af6433
- Bool
- bool(mylist) - not
Sortieren
Mitgliedschaft
- in
Übungen:
https://medium.com/@hannanmentor/pythons-best-code-snippets-c34ed1f07239
Zurück zu Micropython Kurs 2023 - Teil 1
Zurück zur "Micropython Kurs 2023" Startseite
Zurück zur Programmieren Startseite
Zurück zur Wiki Startseite