May 2019
Beginner
528 pages
29h 51m
English
In earlier chapters, you used string methods lower and upper to convert strings to all lowercase or all uppercase letters. You also can change a string’s capitalization with methods capitalize and title.
Method
capitalize copies the original string and returns a new string with only the first letter capitalized (this is sometimes called sentence capitalization):
In [1]: 'happy birthday'.capitalize()Out[1]: 'Happy birthday'
Method title copies the original string and returns a new string with only the first character of each word capitalized (this is sometimes called book-title capitalization):
In [2]: 'strings: ...Read now
Unlock full access