Adjusting Case in Strings in Python

By Hemanta Sundaray on 2021-08-29

upper()

Convert the entire string into uppercase:

forecast = "linear regression"

print(forecast.upper())
# LINEAR REGRESSION

lower()

Convert the entire string into lowercase:

forecast = "LINEAR REGRESSION"

print(forecast.lower())
# linear regression

title()

Capitalize the first letter of each word:

comment = "bad programming is easy."

print(comment.title())
# Bad Programming Is Easy.

capitalize()

Capitalize the first letter of each sentence:

comment = "bad programming is easy."

print(comment.capitalize())
# Bad programming is easy.

Join the Newsletter