.title() - annoying mistake

Grant Edwards grant.b.edwards at gmail.com
Sun Mar 21 11:51:52 EDT 2021


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).

--
Grant




More information about the Python-list mailing list