[Python-de] Re: for unpacking

[email protected] (Stefan Ram) 7 Aug 2024 10:18:08 GMT
Newsgroups gmane.comp.python.general.german
Organization Stefan Ram
Message-ID <[email protected]>
Patrick Rudin <[email protected]> schrieb oder zitierte:
>zahlen = [[5,5,5]]
>zahlen.append([9,9,9])
>
>for t in zahlen:
>     print('vorher: ', id(t[1]))
>     t[1] += t[2]
>     print('nachher:', id(t[1]))

  main.py

zahlen = [[5,5,5]]
zahlen.append([9,9,9])

print( zahlen )
for t in zahlen:
     t[1:2] = [t[1]+t[2]]
print( zahlen )

  Ausgabe

[[5, 5, 5], [9, 9, 9]]
[[5, 10, 5], [9, 18, 9]]

  (Das hatte aber eigentlich weniger mit der Art zu tun, wie
  "for" etwas entpackt, sondern eher damit, wie man die Bindung
  einer Stelle einer Liste verändert.)
_______________________________________________
python-de Mailingliste -- [email protected]
Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an [email protected]
https://mail.python.org/mailman3/lists/python-de.python.org/
Mitgliedsadresse: [email protected]