Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python capitalize() method

Python capitalize() method

Python Strings Python Strings


Description

Python capitalize() converts the first letter of a string to uppercase and all other letters to lowercase. For 8-bit byte encodings, this depends on the local environment.

Syntax

capitalize() method syntax:



str.capitalize()

Parameters

Return Value

This method returns a string with its first letter capitalized.

Example

The following example shows how to use the capitalize() method:

s

=

'

a, B

'

s

.

capitalize

(

)

'

A, b

'

s

=

'

a, B

'

a is preceded by a space

s

.

capitalize

(

)

'

a, b

'

s

=

'

a, BCD

'

s

.

capitalize

(

)

'

A, bcd

'


Python Strings Python Strings