.title() - annoying mistake

Chris Angelico rosuav at gmail.com
Sun Mar 21 18:30:08 EDT 2021


On Mon, Mar 22, 2021 at 9:04 AM Grant Edwards <grant.b.edwards at gmail.com> wrote:
>
> On 2021-03-21, Chris Angelico <rosuav at gmail.com> wrote:
> > On Mon, Mar 22, 2021 at 2:16 AM Robert Latest via Python-list <python-list at python.org> wrote:
> >
> >> I wonder if .title() properly capitalizes titles in any language. It doesn't in
> >> English (nor does it purport to), so it begs the question why it is there in
> >> the first place. German and Spanish don't have any special capitalization rules
> >> for titles; I don't know about any other languages.
> >>
> >
> > It correctly title-cases a single character, as has been pointed out
> > already.
>
> Not according to the docs. The doc states that .title() converts the
> first character characger in each "word" to _upper_ case. Is the doc
> wrong?
>
> If you want titlecase, then you should call str.capitalize() which
> (again according to the doc) converts the first character to _title_
> case (starting in v3.8).
>

Hmm, maybe it's different in 3.10, but the docs I'm seeing look fine.
But maybe there's a better way to word it for both of them.

ChrisA


More information about the Python-list mailing list