14. Lektion: Variablen vielfalt.extend(): Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 6: | Line 6: | ||
** y, x = 1, 2 | ** y, x = 1, 2 | ||
** x, y, z = [1, 2, 3] | ** x, y, z = [1, 2, 3] | ||
** 2) Tuple Unpacking (with & without *) | |||
<pre> | |||
person = ['tom', 5, 'male'] | |||
name, age, gender = person | |||
# name='tom', age=5, gender='male' | |||
We can use tuple unpacking to assign multiple variables in one line. | |||
letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] | |||
first, second, *others = letters | |||
# first='A', second='B' | |||
# letters = ['C', 'D', 'E', 'F', 'G'] | |||
We can add a * character in front of variables to signify that it should contain everything else that hasn’t been unpacked. | |||
</pre> | |||
** Inhalte tauschen | ** Inhalte tauschen | ||
*** x , y = y, x | *** x , y = y, x | ||
| Line 34: | Line 51: | ||
===== Übungen:===== | ===== Übungen:===== | ||
https://medium.com/@hannanmentor/pythons-best-code-snippets-c34ed1f07239 | https://medium.com/@hannanmentor/pythons-best-code-snippets-c34ed1f07239 | ||
Revision as of 10:30, 27 August 2023
Erste Zeile
- Namen
- Bedeutung des _
- __name__ == __main__
- Mehrfach Zuweisung
- y, x = 1, 2
- x, y, z = [1, 2, 3]
- 2) Tuple Unpacking (with & without *)
person = ['tom', 5, 'male'] name, age, gender = person # name='tom', age=5, gender='male' We can use tuple unpacking to assign multiple variables in one line. letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] first, second, *others = letters # first='A', second='B' # letters = ['C', 'D', 'E', 'F', 'G'] We can add a * character in front of variables to signify that it should contain everything else that hasn’t been unpacked.
- Inhalte tauschen
- x , y = y, x
- Inhalte tauschen
- Tupel
- Als Eingabe für Funktionen
- join()
- Als Rückgabewert von Funktionen
- NTP / RTC
- Als Eingabe für Funktionen
- Listen
- Comprehention
- Python's list Data Type
- https://realpython.com/python-list/
- 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