str.upper()

Returns a copy of the string written in uppercase letters.

Returns
A new string in uppercase.
Changes the original
No
On this page

Example

#
Python
course = "python course"
print(course.upper())
print(course)
print("café 🐢".upper())
Resultsaved result, you can check it
PYTHON COURSE
python course
CAFÉ 🐢

Definition and usage

#

The upper() method returns a new string in which every letter is uppercase. The original stays the same, because strings in Python are immutable. You need to assign the result to a variable.

It works correctly with accented characters: "café".upper() is "CAFÉ". Characters that are not letters stay unchanged.

It is often used for case-insensitive comparisons, though the casefold() method is even better for that, since it also handles special cases from other languages.

Syntax

#
Syntax
string.upper()

Good practices

#
  • Remember to assign the result: name = name.upper(). Just calling name.upper() does not change the variable.
  • To check whether a string is already uppercase, use isupper().

Related entries

#

Spotted a mistake or missing an example? Write to us.