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

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 520

Subscribe to our Newsletter

Subscribe to our newsletter and receive all latest projects...

Leave a Reply

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