Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige ÜberarbeitungVorherige Überarbeitung | |||
meins:python:strings-und-print [Sunday, 05. Jun 2016 12:22] – Ivo Schwalbe | meins:python:strings-und-print [Sunday, 05. Jun 2016 12:25] (aktuell) – [Formatter] Ivo Schwalbe | ||
---|---|---|---|
Zeile 82: | Zeile 82: | ||
# 10 Punkte | # 10 Punkte | ||
print " | print " | ||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | # Format als string speichern | ||
+ | formatter = "%r %r %r %r" | ||
+ | |||
+ | # Format mit verschiedenem Inhalt mischen | ||
+ | # Achtung: Geht nur mit %r, weil string, int (und float) | ||
+ | print formatter % (1, 2, 3, 4) | ||
+ | print formatter % (" | ||
+ | print formatter % (True, False, False, True) | ||
+ | print formatter % (formatter, formatter, formatter, formatter) | ||
+ | print formatter % ( | ||
+ | "I had this thing.", | ||
+ | "That you could type up right.", | ||
+ | "But it didn't sing.", | ||
+ | "So I said goodnight." | ||
+ | ) | ||
</ | </ |