Example 1 — Unpack an HTTP Request Line
A request line has three space-separated fields. Split it on whitespace, then compare with splitting on a slash and limiting the number of splits.
line = b"GET /docs/intro HTTP/1.1"
method, target, version = line.split()
print(method, target, version)
print(line.split(b"/"))
print(line.split(b" ", 1)) How It Works
- Unpack directly. Exactly three fields come back, so they unpack into three names.
- Any separator. Splitting on
b"/"cuts in three places, and the spaces stay inside the pieces. - Limit the cuts.
maxsplit=1separates the method and keeps the rest of the line together.

