Our June 2021 cohorts are filling up quickly. Join our free webinar to Uplevel your career
About usWhy usInstructorsReviewsCostFAQContactBlogRegister for Webinar

The upper() Function in Python

Python supports object-oriented programming and has a concise, readable, and easy-to-learn syntax. It is no wonder that it is one of the most popular programming languages. An integral part of Python are its built-in functions. You would have surely used some of these functions in your programs. 

We've written a series of articles to help you learn and brush up on the most useful Python functions. In this article, we’ll learn about Python's upper() function and how to use it. 

If you are preparing for a tech interview, check out our technical interview checklist, interview questions page, and salary negotiation e-book to get interview-ready! Also, read Python String join() Method, Python Exit commands, and Type and Isinstance In Python for more content on Python coding interview preparation.

Having trained over 10,000 software engineers, we know what it takes to crack the most challenging tech interviews. Since 2014, Interview Kickstart alums have landed lucrative offers from FAANG and Tier-1 tech companies, with an average salary hike of 49%. The highest ever offer received by an IK alum is a whopping $1.267 Million!

At IK, you get the unique opportunity to learn from expert instructors who are hiring managers and tech leads at Google, Facebook, Apple, and other top Silicon Valley tech companies.

Want to nail your next tech interview? Sign up for our FREE Webinar.

In this article, we’ll cover:

  • What Is the upper() Function in Python and What Does It Do?
  • The upper() Function in Python: Syntax
  • The upper() Function in Python: Example
  • FAQs on the Upper Case Function upper() in Python

What Is the upper() Function in Python and What Does It Do?

Python’s upper() function converts all the lowercase characters in a string to uppercase characters and returns the modified string. One common application of the upper() function in Python is to check if the given two strings are the same or not. We’ll show you how to do this using an example later in the post.

Note: If you want to convert all characters in a string to lowercase, use the Python function lower(). And if you want to swap between lowercase and uppercase, use the swapcase() function in Python. 

The upper() Function in Python: Syntax

string.upper()

stringName.upper()

The upper() function in Python does not take any parameters. Python’s upper() function returns an all uppercase string made by converting all lowercase characters to uppercase from the given string. If there are no lowercase characters in the given string, the original string is returned as-is.

The upper() Function in Python: Example

Here, we take a look at how you can use the Python function upper() next time you need it:

How to Use the upper() Function In Python: Code

stringExample = "I will be converted to UpperCase @123"

print("Original string: " + stringExample)

uppercaseExample = stringExample.upper()

print("String converted to uppercase using upper(): " + uppercaseExample +"\n")

#To check if two strings are the same in meaning using upper()

stringExample1 = "I wiLl be converTed to UpperCASE @123"

stringExample2 = "I will be converted to UpperCase @345!"

print("Strings to be compared with the original string:")

print("String1: " + stringExample1)

print("String2: " + stringExample2)

print("\n")

if(stringExample.upper() == stringExample1.upper()):

    print("String 1 is the same as the original string.")

else:

    print("String 1 is not the same as the original string.")

if(stringExample.upper() == stringExample2.upper()):

    print("String 2 is the same as the original string.")

else:

    print("String 2 is not the same as the original string.")

Output

Original string: I will be converted to UpperCase @123

String converted to uppercase using upper(): I WILL BE CONVERTED TO UPPERCASE @123


Strings to be compared with the original string:

String1: I wiLl be converTed to UpperCASE @123

String2: I will be converted to UpperCase @345!


String 1 is the same as the original string.

String 2 is not the same as the original string.

Found this article helpful? You can learn about more Python functions in our learn folder. 

FAQs on the Upper Case Function upper() in Python

Q1. Does the upper() function in Python take any parameters?

No, the upper() function acts on a string and does not take any parameters.

Q2. What does the upper() function in Python return?

Python’s upper() function returns the original string converted to all uppercase.

Q3. How does the upper() function in Python work?

Python’s upper() function converts any lowercase characters into uppercase and does nothing to other characters in the original string.

Q4. What are upper() and lower() functions in Python?

Both upper() and lower() functions are built-in functions for string handling in Python. For a given string, upper() converts the string to all uppercase, while lower() converts the string to all lowercase. 

Q5. How does Python determine uppercase?

Python determines uppercase with the help of the isupper() function in Python.

Ready to Nail Your Next Coding Interview?

Whether you’re a coding engineer gunning for a software developer or software engineer role, a tech lead, or you’re targeting management positions at top companies, IK offers courses specifically designed for your needs to help you with your technical interview preparation!

If you’re looking for guidance and help with getting started, sign up for our FREE webinar. As pioneers in the field of technical interview preparation, we have trained thousands of software engineers to crack the most challenging coding interviews and land jobs at their dream companies, such as Google, Facebook, Apple, Netflix, Amazon, and more!

Sign up now!






Attend our Free Webinar on How to Nail Your Next Technical Interview

Recommended Posts

All Posts