gpt4 book ai didi

python - some_string 中的 empty_string - 总是正确的?

转载 作者:太空狗 更新时间:2023-10-29 20:50:19 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why empty string is on every string?

我想知道为什么每当我检查空字符串是否在字符串中时 Python 都会返回 True,以及为什么它的索引为零。

例如:

  • '' in '' => true
  • ''.index('') => 0
  • '' in 'notEmpty' => true
  • 'notEmpty'.index('') => 0

我在编写 ROT13 函数时注意到它,并对其进行测试我发现当我在空字符串上调用它时,它返回 'n' ('n' 是字母表中的 index13)。

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