Python String Methods

Master the essential methods for manipulating and working with Python strings efficiently.

capitalize()
Capitalizes the first character of a string
str.capitalize()
Essential

capitalize()

Capitalizes the first character of a string

Essential

Example

Capitalize the first letter of text:

text = "hello world"
capitalized_text = text.capitalize()

print(capitalized_text)
# Output: 'Hello world'

Definition and Usage

The capitalize() method returns a copy of the string with its first character capitalized and the rest lowercased.

Syntax

str.capitalize()

Parameter Values

Parameter Description
None Not applicable The method operates on the string instance it is called on.