Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Sample Python Code in

This short document demonstrates embedding Python code using the listings package.

Example

The following snippet defines a simple function and prints a few values:

import math

def circle_metrics(radius: float) -> tuple[float, float]:
    """Return circumference and area for a circle with the given radius."""
    circumference = 2 * math.pi * radius
    area = math.pi * radius**2
    return circumference, area

for r in (1, 2.5, 5):
    c, a = circle_metrics(r)
    print(f"r={r:.1f} -> circumference={c:.3f}, area={a:.3f}")

Simple Python sample