Reference library
Python code samples
Easy snippets you can copy, study, and run in the browser editor.
Sponsored
Reserved space — layout preview until AdSense is connected
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
Errors & debugging
easy
Try/except ValueError
Convert user input to int inside try/except and show a friendly message.
errors
try-except
input
Python
raw = "42"
try:
value = int(raw)
print(f"Parsed: {value}")
except ValueError:
print(f"Could not parse {raw!r} as an integer.")
3
0
Open
Browse by section
Each section groups closely related Python snippets.