python - 什么时候 `string.swapcase().swapcase()` 不等于 `string` ?

标签 python python-3.x string character-encoding character

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ß0053S0073s)

关于python - 什么时候 `string.swapcase().swapcase()` 不等于 `string` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61564284/

相关文章:

Python os.rename windows错误

python - 获取只读 mmap 对象的地址

python - 将十六进制转换为 bin 并放入另一个数组 Python 3

mysql - 在 mysql datetime 和 python timestamp 之间转换的正确方法是什么?

python-3.x - 使用重复模式填充 python pandas 数据框中的缺失行

python - 尝试使用字典和 map 转换包含特定文本的行时遇到问题

c - C 中随机名称按字母顺序排序

java - 如何在避免 NoSuchElementException 错误的同时获取可选值?

python - 创建带有按钮的弹出窗口

python - 如何设置Excel选项按钮值(通过python)?