gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:09:37 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com