14. Lektion: Variablen vielfalt.extend()

From Attraktor Wiki
Revision as of 12:01, 18 September 2023 by Kapest (talk | contribs) (Erste Zeile)
Jump to navigation Jump to search

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.

https://medium.com/@sarperismetmakas/10-python-shortcuts-6f5c62c53bb1

Sortieren
Mitgliedschaft
  • in
Übungen:

https://medium.com/@hannanmentor/pythons-best-code-snippets-c34ed1f07239