Python Convert String to Uppercase - Examples
Python String to Uppercase
Sometimes, you may need to convert/transform the given string to uppercase. All the lowercase alphabets will be transformed to uppercase alphabets.
To convert String to uppercase, you can use upper() method on the String. In this tutorial, we will learn how to change the case of given string to uppercase.
Syntax of upper() method
The syntax to use upper() method is:
mystring.upper()
upper() method returns the resulting uppercase string.
Examples
1. Convert given string to uppercase
Following is an example python program to convert a string to upper case.
Python Program
mystring = 'Python Examples'
print('Original String :',mystring)
uppercase = mystring.upper()
print('Uppercase String :',uppercase)
Output
Original String : Python Examples
Uppercase String : PYTHON EXAMPLES
2. Convert given string (with all lowercase characters) to uppercase
In this example, we will take a string with all lowercase alphabets. And convert it to uppercase using String.upper().
Python Program
mystring = 'https://pythonexamples.org'
print('Original String :',mystring)
uppercase = mystring.upper()
print('Uppercase String :',uppercase)
Output
Original String : https://pythonexamples.org
Uppercase String : HTTPS://PYTHONEXAMPLES.ORG
Summary
In this tutorial of Python Examples, we learned to transform a given string to uppercase using string.upper() method, with the help of well detailed examples.