Reference library
Python code samples
Copy-ready Python snippets by topic and difficulty — short, focused, and runnable in the browser editor.
Sponsored
Reserved space — layout preview until AdSense is connected
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
Functions & basics
medium
Return multiple values
Return a tuple of results and unpack them at the call site.
functions
return
tuple
Python
def min_max(values):
if not values:
return None, None
return min(values), max(values)
data = [3, 9, 1, 7]
lo, hi = min_max(data)
print(f"range: {lo} .. {hi}")
4
0
Open
Browse by section
Each section groups closely related Python snippets.