Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

Click on this documentation for str.swapcase(), which says:

Return a copy of the string with uppercase characters converted to lowercase and vice versa. Note that it is not necessarily true that s.swapcase().swapcase() == s.

I can't think about an example where s.swapcase().swapcase() != s, would anyone be able to consider one?

1 Answer

0 votes
by (26.4k points)

Look at this simple example:

s = "ß"

print(s.swapcase().swapcase())

output:

ss

ß is German lowercase double s (The right capitalized form would be ß). The explanation for this happens is that Python doesn't "know" or need to characterize an uppercase conversion for each and every Unicode symbol. So it takes the simple course by assessing s.swapcase() as "SS", so in this manner s.swapcase().swapcase() is "ss".

Are you looking for a good python tutorial? Join the python course fast and gain more knowledge in python.

Watch this video tutorial on how to become a professional in python

Browse Categories

...