Skip to content

Commit 422b859

Browse files
claudeschnaitter
authored andcommitted
feat: Add comprehensive f-string formatting examples
Samples of `r`-strings can later be added to the section.
1 parent dee973d commit 422b859

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

900-Cheatsheet.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ text = 'Wie geht\'s?'
104104
erzählung = "Sie sagt: \"So geht das!\""
105105
neue_zeile = "Zeile 1\nZeile 2"
106106
tabulator = "Text\teingerückt\n\tauch eingerückt"
107+
108+
```
109+
## Besondere Python-String
110+
111+
### f-String = Formatierte String
112+
```python
113+
# Variablen für die nachfolgenden Beispiele.
114+
name = "Alice"
115+
alter = 25
116+
kontostand = 14
117+
118+
# Variablen in Strings einfügen
119+
print(f"Hallo, ich bin {name}!") # Hallo, ich bin Alice!
120+
print(f"Ich bin {name} und {alter} Jahre alt") # Ich bin Alice und 25 Jahre alt
121+
122+
# Ausdrücke in f-Strings
123+
a = 17
124+
b = 5
125+
print(f"{a} geteilt durch {b} ist {a//b} mit Rest {a%b}.")
126+
# 17 geteilt durch 5 ist 3 mit Rest 2.
127+
107128
```
108129

109130
## Boolesche Werte

0 commit comments

Comments
 (0)