Function Details: capitalize

Description

Return a capitalized version of the string.

Extended Description


capitalize is a Python string method that converts strings first character to uppercase and remaining characters to lowercase. Works with upper and lower for case transformations. Similar to title but applies only to first character instead of each word. Useful for proper formatting of names, sentences, and text styling. Often used with strip for text cleanup and casefold for more aggressive Unicode case handling. Creates new string instance, preserving original data integrity. Essential for consistent text formatting in user interfaces and content management.


Read More about capitalize from Python Documentation

Function Signature



Module: builtins

Class: str

Parameters



string.capitalize()

First char lowercase
'hello' → 'Hello'
'word' → 'Word'

First char already uppercase
'Hello' → 'Hello'
No change needed

Other chars uppercase
'hELLO' → 'Hello'
'wORLD' → 'World'

Leading whitespace
' hello' → ' hello'
Space remains, next char capitalized

First char numeric
'123abc' → '123abc'
Numbers unchanged

First char special
'!hello' → '!hello'
'@World' → '@world'

Empty string
'' → ''
Returns empty string

Return


Returns a new string with the first character capitalized and the rest lowercased.


Return Type


str

Output

Explanation

This example demonstrates the basic usage of capitalize(). It capitalizes the first letter of the string.