Student Handbook

Student Handbook

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

str.upper

Returns a copy of a string in capitals.

Synopsis

text.upper()

Description

Like lower, upper returns a new string and leaves the original alone.

Return value

A new str.

Example

name = "ada"
print(name.upper())
print(name)

It prints:

ADA
ada

Common mistake

print(upper("ada"))

Python stops with:

NameError: name 'upper' is not defined

upper is a method, not a function on its own. Call it on the string: "ada".upper().

See also

str.lower

str.upper in the Python documentation

Last updated 2 weeks ago