Sponsored Reserved space — layout preview until AdSense is connected

Reference library

Python code samples

Copy-ready Python snippets by topic and difficulty — short, focused, and runnable in the browser editor.

3 matches
Sponsored Reserved space — layout preview until AdSense is connected
Strings & text easy

F-string formatting

Embed variables and expressions inside readable f-strings.

strings f-string formatting
Python
name = "Ada"
score = 97.5
label = f"{name} scored {score:.1f}%"
print(label)
print(f"Next year: {2026 + 1}")
4 1 Open
Strings & text easy

Split and join words

Turn a sentence into tokens, then rebuild it with a custom separator.

strings split join
Python
raw = "python split join example"
words = raw.split()
print(words)

joined = "-".join(words)
print(joined)

csv_line = "red,green,blue"
colors = csv_line.split(",")
print(" | ".join(colors))
5 0 Open
Strings & text easy

Strip and normalize text

Remove stray whitespace and compare user input reliably.

strings strip input
Python
messy = "  Hello, Python!  \n"
clean = messy.strip()
print(repr(clean))

user = "  YES  "
if user.strip().lower() == "yes":
    print("Confirmed")
2 0 Open

Browse by section

Each section groups closely related Python snippets.