ID EN
Built-in Types

title

Python 3.11 🇮🇩 Bahasa Indonesia

Mengembalikan versi string dengan huruf judul yang kata-katanya dimulai dengan karakter huruf besar dan karakter sisanya adalah huruf kecil.

Syntax

PYTHON
str.title()

Contoh

Example 1
PYTHON
>>> 'Hello world'.title()
'Hello World'
Example 2
PYTHON
>>> "they're bill's friends from the UK".title()
"They'Re Bill'S Friends From The Uk"
Example 3
PYTHON
>>> import re
>>> def titlecase(s):
...     return re.sub(r"[A-Za-z]+('[A-Za-z]+)?",
...                   lambda mo: mo.group(0).capitalize(),
...                   s)
...
>>> titlecase("they're bill's friends.")
"They're Bill's Friends."

See Also

string.capwords()