A simple report needs a heading displayed in uppercase.
What You Need to Understand
The str.upper() method creates an uppercase version of text using Unicode casing rules. It returns a new string and can change the number of characters in some cases.
When to Use It
A simple report needs a heading displayed in uppercase.
Step-by-Step Python Example
heading = "Monthly sales report"
print(heading.upper())
print(heading)
How the Example Works
The first line is uppercase; the second confirms the original string has not been mutated.
Example Output
MONTHLY SALES REPORT
Monthly sales report
STATUS: PENDING
A Second Example
Compare this smaller variation with the main example, then experiment with your own values.
status = "pending"
print(f"STATUS: {status.upper()}")
Important Behavior and Edge Cases
Uppercasing is not a reliable way to normalize identifiers across languages. For case-insensitive matching use casefold() when appropriate.
Try It Yourself
Compare "straße".upper() with the original string.
Common Beginner Mistakes
- Uppercasing is not a reliable way to normalize identifiers across languages. For case-insensitive matching use
casefold()when appropriate. - Applying a string method before defining whether text is intended for display, comparison, parsing, or input validation.
Key Takeaways
- The
str.upper()method creates an uppercase version of text using Unicode casing rules. - The first line is uppercase; the second confirms the original string has not been mutated.
- Uppercasing is not a reliable way to normalize identifiers across languages.