Python string uppercase() method with examples

In this Python tutorial, we will discuss, how to use the Python string uppercase() method with a few examples.

We will also see, how to capitalize each word in a string in Python.

Python string uppercase() Method

By using the Python string upper() method we can convert all lowercase characters of a string into uppercase in Python.

To convert any string to uppercase we have a built-in upper() method in Python which will convert lowercase to uppercase.

The function can take any lowercase string as an input and it can produce a string in uppercase as an output.

Example:

  • First of all, We need to take a string value. In the below python code, You can see, I have taken the value as “welcome to python”.
  • Now print the “msg.upper()” and it will return the string in uppercase letter.

Python string uppercase Code

Below represents the python code for string uppercase.

msg = "welcome to python"
print(msg.upper())
  • After writing the above Python code (string uppercase), Ones you will print “msg.uppercase()” then the output will appear as a “WELCOME TO PYTHON” which will return a uppercase string as an output. Also, you can refer to the below screenshot.
Python string uppercase
Python string uppercase

This is how we can use the uppercase() string method in Python.

Capitalize each word in a string in Python

In python, to capitalize each word in a string we will use the built-in method upper() to capitalize all the letters in the string.

Example:

my_string = 'python guides'
print(my_string.upper())

After writing the above Python code (python capitalize each word in a string), Ones you will print “my_string.upper()” then the output will appear ” PYTHON GUIDES “. Here, the string.upper() is used to capitalize each word in the string. Also, you can refer to the below screenshot to capitalize each word in a string.

Python capitalize each word in a string
Python capitalize each word in a string

This is another Python string formatting example, where we saw how to capitalize each word in a string in Python.

This is how to convert a string to uppercase in Python.

In this tutorial, we have learned how to use the Python string uppercase() method. And also we saw, how to capitalize each word in a string in Python.

You may also like the following tutorials: