This commit is contained in:
jonnybravo
2026-09-08 11:02:29 +02:00
commit 3ad8c9b5a6
66 changed files with 6169 additions and 0 deletions
+354
View File
@@ -0,0 +1,354 @@
<html lang="de">
<head><script src="/livereload.js?mindelay=10&amp;v=2&amp;port=1313&amp;path=livereload" data-no-instant defer></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Python String-Präfixe – Hugo Docker CMS</title>
<meta name="description" content="Python String-Präfixe In Python gibt es verschiedene Präfixe für String-Literale, die bestimmen, wie der Interpreter den Inhalt des Strings verarbeitet. Suffixe …">
<meta property="og:title" content="Python String-Präfixe – Hugo Docker CMS">
<meta property="og:description" content="Python String-Präfixe In Python gibt es verschiedene Präfixe für String-Literale, die bestimmen, wie der Interpreter den Inhalt des Strings verarbeitet. Suffixe …">
<meta property="og:type" content="article">
<meta property="og:url" content="https://localhost:1313/string_prefixes/">
<meta property="og:site_name" content="Hugo Docker CMS">
<link rel="stylesheet" href="/css/main.min.css">
</head>
<body>
<header>
<a href="/" class="logo">Hugo Docker CMS</a>
<nav aria-label="Breadcrumb">
<a href="/">← Start</a>
</nav>
</header>
<main>
<article>
<header class="article-header">
<h1>Python String-Präfixe</h1>
<time datetime="2026-09-08">08.09.2026</time>
</header>
<details class="toc" >
<summary>Inhaltsverzeichnis</summary>
<nav id="TableOfContents">
<ul>
<li><a href="#python-string-methoden">Python String-Methoden</a>
<ul>
<li><a href="#1-bereinigen-und-ausrichten">1. Bereinigen und Ausrichten</a></li>
<li><a href="#2-suchen-und-ersetzen">2. Suchen und Ersetzen</a></li>
<li><a href="#3-aufteilen-und-verbinden">3. Aufteilen und Verbinden</a></li>
<li><a href="#4-groß-kleinschreibung-ändern">4. Groß-/Kleinschreibung ändern</a></li>
<li><a href="#5-überprüfungsmethoden-geben-true-oder-false-zurück">5. Überprüfungsmethoden (Geben <code>True</code> oder <code>False</code> zurück)</a></li>
</ul>
</li>
</ul>
</nav>
</details>
<div class="content">
<h1 id="python-string-präfixe">Python String-Präfixe</h1>
<p>In Python gibt es verschiedene Präfixe für String-Literale, die bestimmen, wie der Interpreter den Inhalt des Strings verarbeitet. Suffixe für String-Literale existieren in Python nicht direkt (anders als in Sprachen wie C++), aber es gibt Methoden auf String-Objekten wie <code>.startswith()</code> und <code>.endswith()</code>.</p>
<p>Hier ist die Liste aller String-Präfixe in Python mit Beschreibung und logischen Beispielen:</p>
<table>
<thead>
<tr>
<th style="text-align: left">Präfix</th>
<th style="text-align: left">Beschreibung</th>
<th style="text-align: left">Logisches Beispiel</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left"><strong>Keines</strong></td>
<td style="text-align: left">Standard-Unicode-String (UTF-8 in Python 3). Verarbeitet normale Escape-Sequenzen wie <code>\n</code> oder <code>\t</code>.</td>
<td style="text-align: left"><code>text = &quot;Zeile 1\nZeile 2&quot;</code></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>f</code> / <code>F</code></strong></td>
<td style="text-align: left"><strong>Formatted String (f-string):</strong> Ermöglicht die direkte Einbettung von Python-Ausdrücken und Variablen in geschweiften Klammern <code>{}</code>.</td>
<td style="text-align: left"><code>name = &quot;Welt&quot;\nprint(f&quot;Hallo {name}!&quot;)</code> <em>(Ausgabe: Hallo Welt!)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>r</code> / <code>R</code></strong></td>
<td style="text-align: left"><strong>Raw String:</strong> Behandelt Backslashes <code>\</code> als normale Zeichen und ignoriert Escape-Sequenzen. Ideal für reguläre Ausdrücke oder Dateipfade.</td>
<td style="text-align: left"><code>pfad = r&quot;C:\Users\Name\Documents&quot;</code></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>b</code> / <code>B</code></strong></td>
<td style="text-align: left"><strong>Byte-String:</strong> Erzeugt ein <code>bytes</code>-Objekt statt eines Standard-Strings. Erlaubt nur ASCII-Zeichen (Werte 0-127).</td>
<td style="text-align: left"><code>daten = b&quot;Hallo&quot;</code> <em>(Typ ist <code>bytes</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>u</code> / <code>U</code></strong></td>
<td style="text-align: left"><strong>Unicode-String:</strong> In Python 3 standardmäßig das Standardverhalten. Wird heute hauptsächlich für die Abwärtskompatibilität mit Python 2 verwendet.</td>
<td style="text-align: left"><code>unicode_text = u&quot;Café&quot;</code></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>fr</code> / <code>rf</code></strong></td>
<td style="text-align: left"><strong>Kombination (Raw f-string):</strong> Erlaubt sowohl die Formatierung mit <code>{}</code> als auch die Ignorierung von Escape-Sequenzen.</td>
<td style="text-align: left"><code>ordner = &quot;Bilder&quot;\npfad = fr&quot;C:\{ordner}\bild.png&quot;</code></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>br</code> / <code>rb</code></strong></td>
<td style="text-align: left"><strong>Kombination (Raw Byte-string):</strong> Erzeugt ein Byte-Objekt, bei dem Backslashes nicht als Escape-Sequenzen interpretiert werden.</td>
<td style="text-align: left"><code>regex_bytes = rb&quot;a\nb&quot;</code></td>
</tr>
</tbody>
</table>
<p><em>(Hinweis: Die Groß- und Kleinschreibung der Präfixe ist beliebig, d. h. <code>f&quot;&quot;</code> verhält sich identisch zu <code>F&quot;&quot;</code>.)</em></p>
<h2 id="python-string-methoden">Python String-Methoden</h2>
<p>Hier ist eine Übersicht über die wichtigsten eingebauten Methoden von String-Objekten (<code>str</code>) in Python, sortiert nach ihrer Funktion:</p>
<h3 id="1-bereinigen-und-ausrichten">1. Bereinigen und Ausrichten</h3>
<table>
<thead>
<tr>
<th style="text-align: left">Methode</th>
<th style="text-align: left">Beschreibung</th>
<th style="text-align: left">Logisches Beispiel</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left"><strong><code>strip([chars])</code></strong></td>
<td style="text-align: left">Entfernt führende und folgende Whitespaces (oder die angegebenen Zeichen in <code>chars</code>).</td>
<td style="text-align: left"><code>&quot; hallo &quot;.strip()</code> <em>(Ergebnis: <code>&quot;hallo&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>lstrip([chars])</code></strong></td>
<td style="text-align: left">Entfernt nur führende Whitespaces oder Zeichen.</td>
<td style="text-align: left"><code>&quot; hallo &quot;.lstrip()</code> <em>(Ergebnis: <code>&quot;hallo &quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>rstrip([chars])</code></strong></td>
<td style="text-align: left">Entfernt nur folgende Whitespaces oder Zeichen.</td>
<td style="text-align: left"><code>&quot; hallo &quot;.rstrip()</code> <em>(Ergebnis: <code>&quot; hallo&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>ljust(width[, fillchar])</code></strong></td>
<td style="text-align: left">Richtet den String linksbündig in einem Feld der Breite <code>width</code> aus.</td>
<td style="text-align: left"><code>&quot;test&quot;.ljust(10, &quot;-&quot;)</code> <em>(Ergebnis: <code>&quot;test------&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>rjust(width[, fillchar])</code></strong></td>
<td style="text-align: left">Richtet den String rechtsbündig in einem Feld der Breite <code>width</code> aus.</td>
<td style="text-align: left"><code>&quot;test&quot;.rjust(10, &quot;-&quot;)</code> <em>(Ergebnis: <code>&quot;------test&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>center(width[, fillchar])</code></strong></td>
<td style="text-align: left">Zentriert den String in einem Feld der Breite <code>width</code>.</td>
<td style="text-align: left"><code>&quot;test&quot;.center(10, &quot;-&quot;)</code> <em>(Ergebnis: <code>&quot;---test---&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>zfill(width)</code></strong></td>
<td style="text-align: left">Füllt den String links mit Nullen auf, bis die Breite <code>width</code> erreicht ist.</td>
<td style="text-align: left"><code>&quot;42&quot;.zfill(5)</code> <em>(Ergebnis: <code>&quot;00042&quot;</code>)</em></td>
</tr>
</tbody>
</table>
<h3 id="2-suchen-und-ersetzen">2. Suchen und Ersetzen</h3>
<table>
<thead>
<tr>
<th style="text-align: left">Methode</th>
<th style="text-align: left">Beschreibung</th>
<th style="text-align: left">Logisches Beispiel</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left"><strong><code>replace(old, new[, count])</code></strong></td>
<td style="text-align: left">Ersetzt Vorkommen von <code>old</code> durch <code>new</code>. Optional wird die Anzahl durch <code>count</code> begrenzt.</td>
<td style="text-align: left"><code>&quot;A-B-C&quot;.replace(&quot;-&quot;, &quot;/&quot;)</code> <em>(Ergebnis: <code>&quot;A/B/C&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>find(sub[, start[, end]])</code></strong></td>
<td style="text-align: left">Gibt den niedrigsten Index zurück, an dem <code>sub</code> gefunden wird. Gibt <code>-1</code> zurück, wenn nicht gefunden.</td>
<td style="text-align: left"><code>&quot;hallo&quot;.find(&quot;ll&quot;)</code> <em>(Ergebnis: <code>2</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>rfind(sub[, start[, end]])</code></strong></td>
<td style="text-align: left">Gibt den höchsten Index zurück, an dem <code>sub</code> gefunden wird. Gibt <code>-1</code> zurück, wenn nicht gefunden.</td>
<td style="text-align: left"><code>&quot;hallo&quot;.rfind(&quot;l&quot;)</code> <em>(Ergebnis: <code>3</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>index(sub[, start[, end]])</code></strong></td>
<td style="text-align: left">Wie <code>find()</code>, wirft aber einen <code>ValueError</code>, wenn das Substring nicht gefunden wird.</td>
<td style="text-align: left"><code>&quot;hallo&quot;.index(&quot;x&quot;)</code> <em>(Ergebnis: <code>ValueError</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>rindex(sub[, start[, end]])</code></strong></td>
<td style="text-align: left">Wie <code>rfind()</code>, wirft aber einen <code>ValueError</code>, wenn nicht gefunden.</td>
<td style="text-align: left"><code>&quot;hallo&quot;.rindex(&quot;l&quot;)</code> <em>(Ergebnis: <code>3</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>count(sub[, start[, end]])</code></strong></td>
<td style="text-align: left">Zählt, wie oft das Substring <code>sub</code> im String vorkommt.</td>
<td style="text-align: left"><code>&quot;banane&quot;.count(&quot;an&quot;)</code> <em>(Ergebnis: <code>2</code>)</em></td>
</tr>
</tbody>
</table>
<h3 id="3-aufteilen-und-verbinden">3. Aufteilen und Verbinden</h3>
<table>
<thead>
<tr>
<th style="text-align: left">Methode</th>
<th style="text-align: left">Beschreibung</th>
<th style="text-align: left">Logisches Beispiel</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left"><strong><code>split(sep=None, maxsplit=-1)</code></strong></td>
<td style="text-align: left">Teilt den String an Trennzeichen <code>sep</code> und gibt eine Liste zurück.</td>
<td style="text-align: left"><code>&quot;A,B,C&quot;.split(&quot;,&quot;)</code> <em>(Ergebnis: <code>['A', 'B', 'C']</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>rsplit(sep=None, maxsplit=-1)</code></strong></td>
<td style="text-align: left">Teilt den String vom Ende her auf.</td>
<td style="text-align: left"><code>&quot;A,B,C&quot;.rsplit(&quot;,&quot;, 1)</code> <em>(Ergebnis: <code>['A,B', 'C']</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>splitlines([keepends])</code></strong></td>
<td style="text-align: left">Teilt den String an Zeilenumbrüchen auf.</td>
<td style="text-align: left"><code>&quot;A\nB&quot;.splitlines()</code> <em>(Ergebnis: <code>['A', 'B']</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>join(iterable)</code></strong></td>
<td style="text-align: left">Verbindet die Elemente eines Iterables (z.B. Liste) mit dem String als Trennzeichen.</td>
<td style="text-align: left"><code>&quot;-&quot;.join([&quot;A&quot;, &quot;B&quot;])</code> <em>(Ergebnis: <code>&quot;A-B&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>partition(sep)</code></strong></td>
<td style="text-align: left">Teilt den String beim ersten Vorkommen von <code>sep</code> in ein Tupel: <code>(vor, sep, nach)</code>.</td>
<td style="text-align: left"><code>&quot;A-B-C&quot;.partition(&quot;-&quot;)</code> <em>(Ergebnis: <code>('A', '-', 'B-C')</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>rpartition(sep)</code></strong></td>
<td style="text-align: left">Teilt den String beim letzten Vorkommen von <code>sep</code>.</td>
<td style="text-align: left"><code>&quot;A-B-C&quot;.rpartition(&quot;-&quot;)</code> <em>(Ergebnis: <code>('A-B', '-', 'C')</code>)</em></td>
</tr>
</tbody>
</table>
<h3 id="4-groß-kleinschreibung-ändern">4. Groß-/Kleinschreibung ändern</h3>
<table>
<thead>
<tr>
<th style="text-align: left">Methode</th>
<th style="text-align: left">Beschreibung</th>
<th style="text-align: left">Logisches Beispiel</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left"><strong><code>lower()</code></strong></td>
<td style="text-align: left">Konvertiert alle Zeichen in Kleinbuchstaben.</td>
<td style="text-align: left"><code>&quot;Hallo&quot;.lower()</code> <em>(Ergebnis: <code>&quot;hallo&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>upper()</code></strong></td>
<td style="text-align: left">Konvertiert alle Zeichen in Großbuchstaben.</td>
<td style="text-align: left"><code>&quot;Hallo&quot;.upper()</code> <em>(Ergebnis: <code>&quot;HALLO&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>capitalize()</code></strong></td>
<td style="text-align: left">Setzt das erste Zeichen auf Groß und den Rest auf Klein.</td>
<td style="text-align: left"><code>&quot;hallo welt&quot;.capitalize()</code> <em>(Ergebnis: <code>&quot;Hallo welt&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>title()</code></strong></td>
<td style="text-align: left">Setzt den ersten Buchstaben jedes Wortes auf Groß.</td>
<td style="text-align: left"><code>&quot;hallo welt&quot;.title()</code> <em>(Ergebnis: <code>&quot;Hallo Welt&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>swapcase()</code></strong></td>
<td style="text-align: left">Vertauscht Groß- und Kleinschreibung.</td>
<td style="text-align: left"><code>&quot;HAllo&quot;.swapcase()</code> <em>(Ergebnis: <code>&quot;haLLO&quot;</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>casefold()</code></strong></td>
<td style="text-align: left">Ähnlich wie <code>lower()</code>, ist aber aggressiver beim Entfernen von Groß-/Kleinschreibungsunterschieden (gut für Caseless Matching in Unicode).</td>
<td style="text-align: left"><code>&quot;Straße&quot;.casefold()</code> <em>(Ergebnis: <code>&quot;strasse&quot;</code>)</em></td>
</tr>
</tbody>
</table>
<h3 id="5-überprüfungsmethoden-geben-true-oder-false-zurück">5. Überprüfungsmethoden (Geben <code>True</code> oder <code>False</code> zurück)</h3>
<table>
<thead>
<tr>
<th style="text-align: left">Methode</th>
<th style="text-align: left">Beschreibung</th>
<th style="text-align: left">Logisches Beispiel</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left"><strong><code>startswith(prefix[, start[, end]])</code></strong></td>
<td style="text-align: left">Prüft, ob der String mit <code>prefix</code> beginnt.</td>
<td style="text-align: left"><code>&quot;hallo&quot;.startswith(&quot;ha&quot;)</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>endswith(suffix[, start[, end]])</code></strong></td>
<td style="text-align: left">Prüft, ob der String mit <code>suffix</code> endet.</td>
<td style="text-align: left"><code>&quot;hallo&quot;.endswith(&quot;lo&quot;)</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>isalnum()</code></strong></td>
<td style="text-align: left">Prüft, ob alle Zeichen alphanumerisch sind (Buchstaben und Zahlen) und mindestens ein Zeichen vorhanden ist.</td>
<td style="text-align: left"><code>&quot;Python3&quot;.isalnum()</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>isalpha()</code></strong></td>
<td style="text-align: left">Prüft, ob alle Zeichen Buchstaben sind.</td>
<td style="text-align: left"><code>&quot;Python&quot;.isalpha()</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>isdigit()</code></strong></td>
<td style="text-align: left">Prüft, ob alle Zeichen Ziffern sind (z. B. auch hochgestellte Zahlen).</td>
<td style="text-align: left"><code>&quot;123&quot;.isdigit()</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>isnumeric()</code></strong></td>
<td style="text-align: left">Prüft, ob alle Zeichen numerisch sind (auch Brüche wie ½).</td>
<td style="text-align: left"><code>&quot;½&quot;.isnumeric()</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>isspace()</code></strong></td>
<td style="text-align: left">Prüft, ob der String nur aus Whitespaces (Leerzeichen, Tabs, Zeilenumbrüchen) besteht.</td>
<td style="text-align: left"><code>&quot; \n&quot;.isspace()</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>islower()</code></strong></td>
<td style="text-align: left">Prüft, ob alle buchstabenbasierten Zeichen kleingeschrieben sind.</td>
<td style="text-align: left"><code>&quot;hallo&quot;.islower()</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>isupper()</code></strong></td>
<td style="text-align: left">Prüft, ob alle buchstabenbasierten Zeichen großgeschrieben sind.</td>
<td style="text-align: left"><code>&quot;HALLO&quot;.isupper()</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
<tr>
<td style="text-align: left"><strong><code>istitle()</code></strong></td>
<td style="text-align: left">Prüft, ob der String im Titlecase-Format vorliegt.</td>
<td style="text-align: left"><code>&quot;Hallo Welt&quot;.istitle()</code> <em>(Ergebnis: <code>True</code>)</em></td>
</tr>
</tbody>
</table>
</div>
</article>
</main>
<footer>
<p>Hugo Docker CMS – <a href="/index.xml">RSS</a></p>
</footer>
</body>
</html>