1. What is the upper() Function in Python?
The upper() function is a built-in Python string method that converts all lowercase characters in a string to uppercase. It returns a new string, leaving the original value unchanged. This method is widely used when you need consistent text formatting—especially for headings, case-insensitive comparisons, data cleaning, or standardizing user input.
Non-alphabetic characters such as numbers, spaces, and symbols are not affected, making upper() a safe method for text transformation without altering the overall structure of the string.
2. Python upper() Method: Syntax, Parameters & Return Value
Python upper() Method Syntax
The syntax is extremely simple:
str.upper()
You call the method directly on a string, and it returns an uppercase version of that string.
Python upper() Method Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| None | — | No | The method’s simplicity makes it ideal for everyday string manipulation tasks. |
Python upper() Method Return Value
The upper() method returns a new string
Return type: str
4. Examples of Python’s upper() Method
Below are several practical examples that show how the upper() method behaves in different scenarios. These examples help you understand how Python treats lowercase letters, mixed-case strings, Unicode characters, and even collections like lists.
Example 1: Basic Usage
text = "hello world"
result = text.upper()
print(result)
# Output: HELLO WORLD
Explanation:
Every lowercase character in the string is converted to uppercase, making the entire text appear in capital letters.