Python Program to Capitalize the First Character of a String – 2024

Hey guys, in this blog we will see a Python Program to Capitalize the First Character of a String.

Table of Contents

Example 1: Using list slicing

my_string = "mlp is a good blog."

print(my_string[0].upper() + my_string[1:])

Output

Mlp is a good blog.
  • In this example, we are simply capitalizing the first element of the list using the upper() method.

Example 2: Using the inbuilt method capitalize()

my_string = "mlp is a good blog."

cap_string = my_string.capitalize()

print(cap_string)

Output

Mlp is a good blog.
  • Here we have used the string.capitalize() method which will capitalize the very first character of the string.
  • This method returns a copy of the string with its first character capitalized and the rest lowercased.

Check out our other python programming examples

Leave a Reply

Your email address will not be published. Required fields are marked *