String Methods

str.capitalize()

Titlecase the initial code point and lowercase the remainder, including uppercase acronyms. It does not skip leading whitespace or find the first letter. Useful for simple labels, not locale-aware name formatting. The receiver is immutable; the operation returns a string without modifying it. Do not rely on a new object identity.

Formal Syntax & Structure

python syntaxpython
text.capitalize()

Return Value

str

String containing the transformed text.

Working Example

Example Snippetpython
label = "pYTHON API"print(label.capitalize())print(repr("  READY".capitalize()))print(label)
Python Reference