it:programmiersprache:python:01_strings

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
it:programmiersprache:python:01_strings [05.09.2026 19:56] – [t-Präfix] marschit:programmiersprache:python:01_strings [17.09.2026 07:25] (aktuell) – [f-Präfix] marsch
Zeile 20: Zeile 20:
 ==== u-Präfix (Unicode) ==== ==== u-Präfix (Unicode) ====
  
-<wrap info><wrap em hi>Ab Python 2.0</wrap> [[https://peps.python.org/pep-0100/|PEP 100 – Python Unicode Integration]] ([[https://peps.pythonlang.de/pep-0100/|DE]]) </wrap>+> <wrap em hi>Ab Python 2.0</wrap> [[https://peps.python.org/pep-0100/|PEP 100 – Python Unicode Integration]] ([[https://peps.pythonlang.de/pep-0100/|DE]])
  
 Der Python Quelltext (vor Python 3.0) eines Programms wird gemäß dem ASCII Zeichensatz abgelegt. Wenn man mal von Sonderzeichen wie zum Beispiel den deutschen Umlauten (Ä,Ö,Ü, ...) absieht, kann der Text auch in Unicode (UTF-8) abgelegt werden, da dieser in weiten Bereichen mit dem ASCII Zeichensatz übereinstimmt. Das gilt natürlich nicht für alle Werte die ein Byte [0 ... 255] annehmen kann um ein Zeichen aus dem ASCII Zeichensatz darzustellen. Der Python Quelltext (vor Python 3.0) eines Programms wird gemäß dem ASCII Zeichensatz abgelegt. Wenn man mal von Sonderzeichen wie zum Beispiel den deutschen Umlauten (Ä,Ö,Ü, ...) absieht, kann der Text auch in Unicode (UTF-8) abgelegt werden, da dieser in weiten Bereichen mit dem ASCII Zeichensatz übereinstimmt. Das gilt natürlich nicht für alle Werte die ein Byte [0 ... 255] annehmen kann um ein Zeichen aus dem ASCII Zeichensatz darzustellen.
Zeile 26: Zeile 26:
 Strings die allerdings Unicode Zeichen enthalten, etwa zur String Ausgabe, können in Form eines Strings mit einem Präfix ''u'' bzw. ''U'' angegeben werden. Etwa : '' u'Schöne neue Welt!' ''. Strings die allerdings Unicode Zeichen enthalten, etwa zur String Ausgabe, können in Form eines Strings mit einem Präfix ''u'' bzw. ''U'' angegeben werden. Etwa : '' u'Schöne neue Welt!' ''.
  
-<wrap info><wrap em hi>Ab Python 3.0 </wrap> ist die Angabe eines String-Literals ''%%u''%%'' obsolete, da der Python Quelltext (ab Python 3.0) selbst in Unicode (UTF-8) erfasst wird.</wrap>+> <wrap em hi>Ab Python 3.0</wrap> ist die Angabe eines String-Literals ''%%u''%%'' obsolete, da der Python Quelltext (ab Python 3.0) selbst in Unicode (UTF-8) erfasst wird.
  
  
 ==== b-Präfix (bytes) ==== ==== b-Präfix (bytes) ====
  
-<wrap info><wrap em hi>Ab Python 3.0a1, Ignoriert in 2.7</wrap> [[https://peps.python.org/pep-3137/|PEP 3137 – Immutable Bytes and Mutable Buffer]] ([[https://peps.pythonlang.de/pep-3137/|DE]])</wrap>+> <wrap em hi>Ab Python 3.0a1, Ignoriert in 2.7</wrap> [[https://peps.python.org/pep-3137/|PEP 3137 – Immutable Bytes and Mutable Buffer]] ([[https://peps.pythonlang.de/pep-3137/|DE]])
  
 Zur Angabe eines String-Literals für Byte-Folgen ab Python 3.1 - nicht aber in Python 2.7 übernommen. Zur Angabe eines String-Literals für Byte-Folgen ab Python 3.1 - nicht aber in Python 2.7 übernommen.
Zeile 46: Zeile 46:
 ==== Mit % (Modulo-Operator) ==== ==== Mit % (Modulo-Operator) ====
  
-<wrap info><wrap em hi>Ab Python 1.0 </wrap> </wrap>+> <wrap em hi>Ab Python 1.0</wrap>
  
 Formatierung im Stil von ''printf()'' aus C. Formatierung im Stil von ''printf()'' aus C.
Zeile 52: Zeile 52:
 <WRAP group> <WRAP group>
 <WRAP half column> <WRAP half column>
 +
 +=== Code ===
  
 <code python> <code python>
Zeile 58: Zeile 60:
  
 </WRAP><WRAP half column> </WRAP><WRAP half column>
 +
 +=== Beschreibung ===
  
 Beinhaltet: Beinhaltet:
Zeile 92: Zeile 96:
 ==== $-Präfix ==== ==== $-Präfix ====
  
-<wrap info><wrap em hi>Ab Python 2.1 </wrap> [[https://peps.python.org/pep-0215/|PEP 215 – String Interpolation]] ([[https://peps.pythonlang.de/pep-0215/|DE]]) </wrap>+> <wrap em hi>Ab Python 2.1</wrap> [[https://peps.python.org/pep-0215/|PEP 215 – String Interpolation]] ([[https://peps.pythonlang.de/pep-0215/|DE]]) 
 + 
 +<WRAP group> 
 +<WRAP half column> 
 + 
 +=== Code === 
 + 
 +<code python> 
 + 
 +</code> 
 + 
 +</WRAP><WRAP half column> 
 + 
 +=== Beschreibung === 
 + 
 +</WRAP> 
 +</WRAP>
  
  
 ==== Templates ==== ==== Templates ====
  
-<wrap info><wrap em hi>Ab Python 2.4 </wrap> [[https://www.python.org/dev/peps/pep-0292|PEP 292 – Simpler String Substitutions]] ([[https://peps.pythonlang.de/pep-0292/|DE]])</wrap>+> <wrap em hi>Ab Python 2.4</wrap> [[https://www.python.org/dev/peps/pep-0292|PEP 292 – Simpler String Substitutions]] ([[https://peps.pythonlang.de/pep-0292/|DE]])
  
 Formatierung mit Template-Strings Formatierung mit Template-Strings
Zeile 103: Zeile 123:
 <WRAP group> <WRAP group>
 <WRAP half column> <WRAP half column>
 +
 +=== Code ===
  
 <code python> <code python>
Zeile 113: Zeile 135:
 </WRAP><WRAP half column> </WRAP><WRAP half column>
  
-Beschreibung+=== Beschreibung ===
  
 </WRAP> </WRAP>
Zeile 121: Zeile 143:
 ==== .format()-Style ==== ==== .format()-Style ====
  
-<wrap info><wrap em hi>Ab Python 3.0, Backported to 2.6</wrap> [[https://peps.python.org/pep-3101/|PEP 3101 – Advanced String Formatting]] ([[https://peps.pythonlang.de/pep-0292/|DE]])</wrap>+> <wrap em hi>Ab Python 3.0, Backported to 2.6</wrap> [[https://peps.python.org/pep-3101/|PEP 3101 – Advanced String Formatting]] ([[https://peps.pythonlang.de/pep-0292/|DE]])
  
 Formatierung mit ''str.format()'' Formatierung mit ''str.format()''
Zeile 127: Zeile 149:
 <WRAP group> <WRAP group>
 <WRAP half column> <WRAP half column>
 +
 +=== Code ===
  
 <code python> <code python>
Zeile 133: Zeile 157:
  
 </WRAP><WRAP half column> </WRAP><WRAP half column>
 +
 +=== Beschreibung ===
  
 Sehr leistungsfähig. Sehr leistungsfähig.
Zeile 140: Zeile 166:
  
 ==== f-Präfix ==== ==== f-Präfix ====
 +
 +> <wrap em hi>Ab Python 3.5.3</wrap> [[https://www.python.org/dev/peps/pep-0498/|PEP 498 – Literal String Interpolation]] ([[https://peps.pythonlang.de/pep-0498/|DE]])
 +
 +String Formatierung mit
 +
 +Sollte der Parameter explizit in einen String umgewandelt werden, so sollte statt ''f%%"... {str(param)} ..."%%'' das Conversion-Flag ''f%%"... {param!s} ..."%%'' verwendet werden.\\ 
 +Sollte der Parameter explizit in einen String umgewandelt werden, so sollte statt ''f%%"... {repr(param)} ..."%%'' das Conversion-Flag ''f%%"... {param!r} ..."%%'' verwendet werden.
 +
  
 <WRAP group> <WRAP group>
 <WRAP half column> <WRAP half column>
  
-<wrap info><wrap em hi>Ab Python 3.5.3</wrap> [[https://www.python.org/dev/peps/pep-0498/|PEP 498 – Literal String Interpolation]] ([[https://peps.pythonlang.de/pep-0498/|DE]])</wrap> +=== Code ===
- +
-String Formatierung mit+
  
 <code python> <code python>
-f'A String {} with format'+param = 3.14 
 + 
 +print(f"Math PI = {param}")
 </code> </code>
  
 </WRAP><WRAP half column> </WRAP><WRAP half column>
  
-Beschreibung+=== Beschreibung ===
  
 </WRAP> </WRAP>
Zeile 162: Zeile 196:
 ==== t-Präfix ==== ==== t-Präfix ====
  
-<wrap info><wrap em hi>Ab Python 3.14 </wrap> [[https://www.python.org/dev/peps/pep-0750/|PEP 750 – Template Strings]] ([[https://peps.pythonlang.de/pep-0750/|DE]])</wrap>+> <wrap em hi>Ab Python 3.14</wrap> [[https://www.python.org/dev/peps/pep-0750/|PEP 750 – Template Strings]] ([[https://peps.pythonlang.de/pep-0750/|DE]])
  
 String Formatierung mit t-Präfix. Es besteht eine Ähnlichkeit mit [[#f-Präfix]], jedoch bleibt der Platzhalter im String erhalten und kann wiederverwendet werden. String Formatierung mit t-Präfix. Es besteht eine Ähnlichkeit mit [[#f-Präfix]], jedoch bleibt der Platzhalter im String erhalten und kann wiederverwendet werden.
  • it/programmiersprache/python/01_strings.1788638168.txt.gz
  • Zuletzt geändert: 05.09.2026 19:56
  • von marsch