Python string to Uppercase – str.upper()

Filed Under: Python

We can convert a string to uppercase in Python using str.upper() function. In this short tutorial, we will learn how to convert python string to uppercase.

Python String to Uppercase

Let’s look at a simple example of converting a string to uppercase and print it.


s = 'abcDEF%$'

print('Uppercase String =', s.upper())
print('Original String =', s)

Output:


Uppercase String = ABCDEF%$
Original String = abcDEF%$

Notice that when we call upper() on a string object, the original string remains unchanged. This function creates another string with uppercase characters and returns it.

Python String upper() with user input

Let’s have a look at another example where we will get the user input and convert it to uppercase and print it.


s = input('Please Provide Input String\n')

print('Input String in Uppercase =', s.upper())

print('Original String =', s)

Output:


Please Provide Input String
JournalDev is Awesome!!
Input String in Uppercase = JOURNALDEV IS AWESOME!!
Original String = JournalDev is Awesome!!

python string to uppercase

You can checkout complete python script and more Python examples from our GitHub Repository.

Reference: API Doc

Leave a Reply

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

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages