swapcase And istitle Validate Casing
Flip letter case in place with str.swapcase and gate display rules with istitle, isupper, and islower, which all return False for empty or digit-only strings.
Code
codes = ["HTTP", "12ab", "1234", ""]
print([c.isupper() for c in codes]) # True False False False
# 纯数字与空串不满足任何大小写判定,全部 False
print([c.islower() for c in codes])
# istitle 要求每个单词首字母大写
print("Spring Boot".istitle(), "Spring boot".istitle())
# swapcase 交换大小写并往返一致
toggled = "Proxy-Auth".swapcase()
print(toggled, toggled.swapcase())
# 宽松化输入前先看原始形态再决定是否归一
raw = "MiXeD CaSe"
normal = raw.lower()
print("changed:", raw != normal, normal)Output
Captured from a sandboxed run of this snippet in the build pipeline.
[True, False, False, False]
[False, True, False, False]
True False
pROXY-aUTH Proxy-Auth
changed: True mixed caseInside the snippet
The file’s state is a handful of top-level bindings: codes, toggled, raw, normal.
What to watch for
- The runtime is the only requirement — no packages, no install.
Putting it to use
Output lines are prefixed (Spring Boot, changed:), so every step’s effect shows up right where its line prints.
Interactive Tools for This Topic
JSON to Zod Schema ConverterInfer typed Zod z.object schemas from JSON payloads locally, supporting nested objects, merged array shapes, enums, nullable fields, and JSDoc comments.JSON Schema ValidatorValidate JSON data against a JSON Schema definition and get detailed error reports. Supports type checking, required fields, and common constraint validation.JSONL / NDJSON InspectorValidate NDJSON and JSON Lines line-by-line, pinpoint syntax errors by line number, analyze key frequencies and types, and export a pretty JSON array.Credit Card Brand DetectorIdentify the card network from a number's prefix and length, validate the Luhn checksum, and show a masked form and the issuer identification number.
FAQ
- Anything to download besides the language toolchain?
- Nothing beyond the toolchain you already have for this language. Its state lives in module-level bindings: `codes`, `toggled`, `raw`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.