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.
Code
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 | regionWhat 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
Git Conventional Commit BuilderBuild and validate Conventional Commits v1.0.0 messages with type, scope, breaking markers, 72-char subject counter, body, footers, and git CLI command.Glob Pattern TesterCompile glob patterns with *, **, ?, character classes, and braces into regex and test them against a list of candidate file paths.Tar Archive Command BuilderBuild safe tar create, extract, and list commands for gzip, xz, zstd, and bzip2 archives with excludes, target directory (-C), and flag explanations.
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`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.