On this page
string.capwords
Up: string | Next: string.Formatter
Rel: string.Formatter, string.Template
Ref: docs.python.org — string.capwords
Tags: #public #python3 #stdlib #string
Import
import string
from string import capwords
Signature & Overview
string.capwords(s, sep=None)
Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. If the optional second argument sep is absent or None,
Usage
import string
assert string.capwords("they're here") == "They're Here"
Gotchas
- Fixes
str.title()'s apostrophe bug ("they're".title()gives"They'Re"), and collapses whitespace runs.
REPL Inspect
from string import capwords
help(capwords)
Linked from
Related notes
- tuts/python3/stdlib_module/string/Formatter Linked here; links to this page; shared tags: #stdlib, #string
- tuts/python3/stdlib_module/string/Template Linked here; links to this page; shared tags: #stdlib, #string
- tuts/python3/stdlib_module/string Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib/string shared tags: #stdlib, #string
- tuts/c/stdlib/string/memchr shared tags: #stdlib, #string
- tuts/c/stdlib/string/memcmp shared tags: #stdlib, #string
- tuts/c/stdlib/string/memcpy shared tags: #stdlib, #string
- tuts/c/stdlib/string/memmove shared tags: #stdlib, #string
- tuts/c/stdlib/string/memset shared tags: #stdlib, #string
- tuts/c/stdlib/string/strcat shared tags: #stdlib, #string