Convert First Character of String to Uppercase in Python

Convert the first character of a string to uppercase in Python; Through this tutorial, i am going to show you how to capitalize string first character or convert string first character/letter to uppercase in Python.

How to Capitalize First Character of String in Python

You can use capitalize() method of python to capitalize first letter of string in python or convert the first character of a string to uppercase in Python.

  • Python String capitalize() Method
  • Parameter of Python capitalize() Method
  • Return Value from capitalize()
  • Example 1: To capitalize first letter of string in python
  • Example 2: Convert First Character of String To Uppercase in Python

Python String capitalize() Method

Python capitalize method is one of the Python String Method, which is used to convert the first character into Uppercase and remaining characters to Lowercase and return a new string.

The syntax of capitalize() is:

string.capitalize()

Parameter of Python capitalize() Method

The capitalize() function doesn’t take any parameter.

Return Value from capitalize()

The capitalize() function returns a string with first letter capitalized and all other characters lowercased. It doesn’t modify the original string.

Now you know that How to convert first character/letter of string to uppercase in Python. So now we discuss how to write a capitalize Function in Python programs with an example:

Example 1: To capitalize first letter of string in python

string = "python is AWesome."
capitalized_string = string.capitalize()
print('Old String: ', string)
print('Capitalized String:', capitalized_string)

Example 2: Convert First Character of String To Uppercase in Python

string = "this + is an operator."
new_string = string.capitalize()
print('Old String:', string)
print('New String:', new_string)

Recommended Python Tutorials

Recommended:-Functions in Python
Recommended:-Python Modules
Recommended:-Python Lists
Recommended:-Python Strings

Be First to Comment

Leave a Reply

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