作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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/
Documentation对于 str.swapcase() 方法说: Return a copy of the string with uppercase characters converted
str.swapcase() 的 Python 文档说: Note that it is not necessarily true that s.swapcase().swapcase() == s.
我是一名优秀的程序员,十分优秀!