.swapcase()

Anonymous contributor's avatar'
Anonymous contributor
Anonymous contributor's avatar'
Anonymous contributor
Published Jun 10, 2021Updated Sep 3, 2021
Contribute to Docs

Takes a string and returns a copy of that string in which all lowercase letters are uppercase, and all upercase letters are lowercase. Numbers and symbols are not changed.

Syntax

string.swapcase()

Example 1

message = "Hello, World!"
new_string = message.swapcase()
print(new_string)
# Output: "hELLO, wORLD!"

Example 2

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

Code
Output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy