str.join Builds One Separated String

str.join is the separator method: it accepts any iterable of strings, requires conversion for numbers, and yields an empty string for an empty iterable.

PythonCli Tooling

Code

pythonsnippet
13 lines
parts = ["deploy", "web.prod", "2026-11-21"]
print("dashed:", "-".join(parts))

# non-string elements must be converted first; join performs no implicit conversion
ports = [80, 443, 8080]
print("ports:", ", ".join(str(p) for p in ports))

# join belongs to the separator itself: an empty iterable yields an empty string
print("empty:", "|".join([]))

# any separator works: joining header cells or path fragments alike
fields = ["name", "role", "region"]
print("header:", " | ".join(fields))

Output

Captured from a sandboxed run of this snippet in the build pipeline.

dashed: deploy-web.prod-2026-11-21
ports: 80, 443, 8080
empty: 
header: name | role | region

What the code does

Demo state sits in top-level bindings: parts, ports, fields.

Watch out for

  • All of its symbols are language built-ins — nothing needs fetching.

Applying it

The run emits 4 labeled sections — dashed:, ports:, empty:, header: — one per step.

Interactive Tools for This Topic

FAQ

Are there third-party dependencies?
No. The dependency list is empty; the code stays inside the standard library. Its state lives in module-level bindings: `parts`, `ports`, `fields`.