What is the difference? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the difference?

What is the difference between capitalize and title? It seems they do the same thing. Try this code? mystring = '4sDgg5' print(mystring.capitalize()) print(mystring.title())

1st Aug 2018, 7:45 PM
Shuaib Nuruddin
Shuaib Nuruddin - avatar
2 Answers
+ 5
Title will capitalize the first letter of every word in the string, Capitalize will capitalize the first letter of the first word of a string. ie, x 'hello world' x.title() = Hello World x.capitalize() = Hello world
1st Aug 2018, 8:02 PM
JME
+ 1
Try using both .capitalize() & .title() for space-separated strings, you will notice the difference.
2nd Aug 2018, 4:54 AM
E_E Mopho
E_E Mopho - avatar