split() Collapses Whitespace And rsplit Limits Splits
No-argument split() treats any whitespace run as one separator and drops the edges, while rsplit with maxsplit keeps the left side intact for extension splits.
Code
line = " deploy web.prod --wait\n"
# split() with no arguments: any run of whitespace counts as one separator, and leading/trailing whitespace is dropped
print("no-arg:", line.split())
# explicit " " separator: consecutive spaces produce empty strings
print("space:", "a b".split(" "))
# rsplit cuts from the right and maxsplit caps the count: the left side stays intact
spec = "app.web.prod.internal"
print("rsplit:", spec.rsplit(".", 1))
print("split:", spec.split(".", 1))
# typical use: split the extension off the right side of a filename
filename = "report-2026-11-21.final.pdf"
stem, ext = filename.rsplit(".", 1)
print("stem:", stem)
print("ext:", ext)Output
Captured from a sandboxed run of this snippet in the build pipeline.
no-arg: ['deploy', 'web.prod', '--wait']
space: ['a', '', 'b']
rsplit: ['app.web.prod', 'internal']
split: ['app', 'web.prod.internal']
stem: report-2026-11-21.final
ext: pdfThe way the file runs
The file’s state is a handful of top-level bindings: line, spec, filename.
What to watch for
- The runtime alone is required here — no packages, no install step.
Putting it to use
Each step the file takes is announced in the output: no-arg:, space:, rsplit:.
Interactive Tools for This Topic
Diff Ignoring WhitespaceCompare two blocks of text line by line and separate true differences from lines that differ only in spacing, indentation, or line endings.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
- Does the runtime need any help from npm, pip, cargo, or the like?
- No — the package manager has nothing to do here; nothing is declared. Its state lives in module-level bindings: `line`, `spec`, `filename`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.