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
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
Functions & basics
easy
Function with default argument
Define a reusable greet helper with an optional prefix parameter.
functions
defaults
basics
Python
def greet(name, prefix="Hello"):
return f"{prefix}, {name}!"
print(greet("Python"))
print(greet("World", prefix="Hi"))
3
0
Open
Browse by section
Each section groups closely related Python snippets.