Python .upper()

grace_k's avatar
Published Jun 8, 2021Updated Jan 7, 2023
Contribute to Docs

The .upper() method takes a string and returns a copy of that string in which all letters are uppercase. Numbers and symbols are not changed.

Note: The .upper() method does not change the string it is used on.

  • Learn to analyze and visualize data using Python and statistics.
    • Includes 8 Courses
    • With Certificate
    • Intermediate.
      13 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

Syntax

string.upper()

Example

The following example shows how .upper() returns a string with all its letters in uppercase. It also shows that the original string remains unchanged:

my_string = "shout"
print(my_string)
print(my_string.upper())
print(my_string)

This would output:

shout
SHOUT
shout

Codebyte Example

The following example shows how the .upper() method can be used to compare strings:

Code
Output

All contributors

Contribute to Docs

Learn Python on Codecademy

  • Learn to analyze and visualize data using Python and statistics.
    • Includes 8 Courses
    • With Certificate
    • Intermediate.
      13 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours