Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any difference between str.capitalize() and str.title()?

Is there any difference in str.title() vs str.capitalize()? My understanding from the docs is that both methods capitalize the first letter of a word and make the rest of the letters lowercase. Did anyone run into a situation where they cannot be used interchangeably?

like image 489
mysl Avatar asked Dec 18 '19 03:12

mysl


1 Answers

title() changes every word, but capitalize() only the first word in a sentence:

>>> a = 'silly question'
>>> a.title()
'Silly Question'
>>> a.capitalize()
'Silly question'
>>> 
like image 149
lenik Avatar answered Oct 14 '22 00:10

lenik