Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige ÜberarbeitungVorherige Überarbeitung
meins:python:strings-und-print [Sunday, 05. Jun 2016 12:22] Ivo Schwalbemeins:python:strings-und-print [Sunday, 05. Jun 2016 12:25] (aktuell) – [Formatter] Ivo Schwalbe
Zeile 82: Zeile 82:
 # 10 Punkte # 10 Punkte
 print "." * 10 print "." * 10
 +</code>
 +
 +<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 % ("one", "two", "three", "four")
 +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."
 +)
 </code> </code>