Case Change: capitalize(), capwords(), swapcases(), lower(), upper()

The capitalize(word) function capitalizes a given word in a string.

>>> capitalize("bill")
'Bill'

The capwords(s) function capitalizes all words in a string.

>>> str = "bill joy"
>>> str = capwords(str)
>>> print str
Bill Joy

The swapcases(s) function converts uppercase letters to lowercase letters and vice versa.

>>> swapcase("ABC abc 123")
'abc ABC 123'

(Frankly, I don't see the value of this one.)

The lower(s) function converts uppercase letters to lowercase letters.

>>> lower("ABC abc 123")
'abc abc 123'

The upper(s) function converts lowercase letters to uppercase letters.

>>> upper("ABC abc 123")
'ABC ABC 123'

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.