Python string to upper, lower or capitalize

Python string supports methods which make very easy the converting string to upper or lower case. This is done by methods:

  • upper() - convert all letters to uppercase rome -> ROME
  • capitalize() - Capitalize words - rome -> Rome
  • lower() - changing all letters to lowercase - RoME -> rome

Python convert string to lowercase

Convert all letters in string to upper case:

string="Rome Is a nice city!"
print(string.upper())

result:

ROME IS A NICE CITY!

Python convert string to lowercase

Change only the first letter of the string to capital letter and all the rest to lower case:

string="rOme iS a nice city"
print(string.capitalize())

result:

Rome is a nice city

Python convert string to lowercase

Converting all letters to lowercase in python.

string="rOme iS a nice city"
print(string.lower())

result:

rome is a nice city

Related Article