Convert First Character of String into Uppercase in Python

Last updated on January 16, 2023

You can convert the first character into uppercase through capitalize() method. To use the capitalize() method you need to create a variable for storing string value and then access through dot notation.

Look at the example below in which we have a string containing lowercase values. Let’s convert the first character of the below string into uppercase.

favouriteLanguage = "python is my favorite programming language."
convertedString = favouriteLanguage.capitalize()
print(convertedString)
# Output: Python is my favorite programming language.

In this example, we have a string stored into variable favouriteLanguage. Here python attaches built-in function with favouriteLanguage variable and capitalize() method is one of them. So we can access the capitalize() method through a dot that converts the first character into uppercase. That’s why we got Capital P in the output along with the string.


Written by
I am a skilled full-stack developer with extensive experience in creating and deploying large and small-scale applications. My expertise spans front-end and back-end technologies, along with database management and server-side programming.

Share on:

Related Posts

Tags: Python, String,