Documentation对于 str.swapcase() 方法说:
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.
我想不出一个 s.swapcase().swapcase() != s
的例子,有人能想到一个吗?
最佳答案
一个简单的例子是:
s = "ß"
print(s.swapcase().swapcase())
Ouput:
ss
ß
is German lowercase double s (“正确的”大写版本是 ẞ
)。发生这种情况的原因是Unicode standard已将 ß
的大写定义为 SS
:
The data in this file, combined with # the simple case mappings in UnicodeData.txt, defines the full case mappings # Lowercase_Mapping (lc), Titlecase_Mapping (tc), and Uppercase_Mapping (uc). ... # The entries in this file are in the following machine-readable format: # # <code>; <lower>; <title>; <upper>; (<condition_list>;)? # <comment> ... # The German es-zed is special--the normal mapping is to SS. # Note: the titlecase should never occur in practice. It is equal to titlecase(uppercase(<es-zed>)) 00DF; 00DF; 0053 0073; 0053 0053; # LATIN SMALL LETTER SHARP S
(00DF
为 ß
,0053
为 S
,0073
为s
)
关于python - 什么时候 `string.swapcase().swapcase()` 不等于 `string` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61564284/