transformation
str.upper
Returns a copy of the string with all cased characters converted to uppercase. Non-cased characters (digits, punctuation, whitespace) are unchanged.
str.upper() Parameters
| Parameter | Purpose |
|---|---|
| self | operates on the calling string; takes no arguments |
| returns | new uppercased str (original is unchanged — str is immutable) |
Examples
>>> 'Hello, World!'.upper()
'HELLO, WORLD!' only cased letters change
>>> 'straße'.upper()
'STRASSE' German ß expands to 'SS' (length can change)
>>> '123 abc'.upper()
'123 ABC' digits untouched
>>> 'áéí'.upper()
'ÁÉÍ' accented Unicode letters are handled
Gotcha
Result length can change (e.g. 'ß' becomes 'SS'), so upper() is not safe for case-insensitive comparison — use casefold().
Related methods
str.lower
Returns a copy of the string with all cased characters converted to lowercase. Uses Unicode simple lowercase mappings.
str.casefold
Returns a casefolded copy suitable for caseless matching. Stronger than lower(): it applies full Unicode case folding, e.g. German 'ß' becomes 'ss'.
str.title
Returns a titlecased copy where the first letter of each word is uppercase and the rest are lowercase. Word boundaries are defined by any run of non-letter characters, including apostrophes.
str.replace
Returns a new string with all occurrences of substring old replaced by new. If count is given, only the first count occurrences are replaced.