Converts first character to upper case Python

Converts first character to upper case Python

Python Tutorial

In certain applications, we need to manipulate words, one of which is Converts the first character to upper case Python.

For example, we have a sentence like this:

this is beautiful!

We want the sentence to be like this:

This is beautiful!

To do this automatically, in the Python programming language we use the function capitalize().

How to use it?

This function will return the first character to be capitalized, the rest are lowercase.

To use it, consider the following examples:

First Example

text = "this is beautiful!"
x = text.capitalize()

print (x)

The result is:

This is beautiful!

Second example

text = "THIS IS BEAUTIFUL!"
x = text.capitalize()

print (x)

The result is:

This is beautiful!

Third example

text = "ThIs iS BeaUtIfuL!"
x = text.capitalize()

print (x)

The result is:

This is beautiful!

but it has no effect on numbers, for example the following fourth example:

Fourth example

text = "1980s as a successor to the ABC programming language and first released it in 1991 as Python 0.9.0"
x = text.capitalize()

print (x)

The result is:

1980s as a successor to the abc programming language and first released it in 1991 as python 0.9.0

For more function about manipulated of string, please go to How to manipulated String in Python here.

Hopefully this Converts first character to upper article is useful.

READ NEXT

4 thoughts on “Converts first character to upper case Python”

  1. Pingback: Converts string into lower case Python - CHIPPIKO

  2. Pingback: How to Returns a centered string in Python - CHIPPIKO

  3. Pingback: How to Manipulate String in Python - CHIPPIKO

  4. Pingback: How to count word in string Python - CHIPPIKO

Leave a Comment

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

Scroll to Top