This post will discuss how to convert the first character of a string to uppercase in Python.

1. Using str.title() function

You can use str.title() to get a title cased version of the string. This converts the first character of each word in the string to uppercase and the remaining characters to lowercase. The following example demonstrates this.

Download  Run Code

2. Using str.capitalize() function

You can use str.capitalize() to get a string with its first character capitalized and remaining characters lowercased, as demonstrated in the following example:

Download  Run Code

3. Using Slicing

If you just need to convert the first character to uppercase and leaving other characters untouched, you can use the upper() function with slicing, as shown below:

Download  Run Code

That’s all about converting the first character of a string to uppercase in Python.