当字符串首位是空格时,使用 str.find()的返回值与普通字符串不一致。

5TuNan:Python 中字符串中有空格时,使用 str.find() 与 没有空格使用 find,返回的值是不一样的。有没有大佬给解释一下为什么,非常感谢。
代码如下

a = 'afbf'
print(a.find('f', 2))  # 打印: 4
b = ' afbf'
print(b.find('f', 2))  # 打印: 2

also24:是不是没注意 find 方法的第二个参数?

SingeeKing:难道市面上出现了盗版的 Python……

当字符串首位是空格时,使用 str.find()的返回值与普通字符串不一致。

also24:补个链接:

https://docs.python.org/zh-cn/3/library/stdtypes.html?highlight=str%20find#str.find

ipwx:楼主你…… 居然以为 find 的第二个参数是“寻找第二个出现的 xxx”。。。

chocovon:第一个怎么打印出 4 的……

ipwx:@chocovon
@SingeeKing 肯定有不可见 unicode 字符呗。。。

PHP str_replace数组 - php

我有一个关于将数组返回为特殊字符串的问题。因此,这是我尝试过的代码。$setValues = array("test1", "test2", "testurl"); $change = join("','", $setValues); $done = str_…

等同于setup.py中的--find-links - python

--find-links中-f的pip / setup.py标志的等效项是什么。我知道dependency_links存在,但是需要指向一个特定的文件,我想要一个类似于-f的东西,它可以指向一个链接列表,可以根据版本和操作系统从中选择软件包。 参考方案 在setuptools上下文中,dependency_links选项应该可以满足您的需求。根据setupt…

浮动子类以更改摄入量和__str__行为 - python

我将float子类化,以更改其__str__()方法以符号结尾(在我的情况下为€)。输入经过过滤以删除符号(在我的情况下为€)。class Euro(float): def __new__(cls, value): v = ''.join([_ for _ in value if _ != '€' ]) return …

PHP str_replace是否具有大于13个字符的限制? - php

直到击中第13个字符为止。一旦str_ireplace在cyper数组中击中“ a”,str_ireplace就停止工作。数组的大小有限制吗?请记住,如果键入“ abgf”,我会得到“ nots”,但是如果键入“ abgrf”,我应该得到“ notes”,那么我就会得到“ notrs”。机架使我的大脑无法解决。$_cypher = array("n…

TypeError:'str'对象不支持项目分配,带有json文件的python - python

以下是我的代码import json with open('johns.json', 'r') as q: l = q.read() data = json.loads(l) data['john'] = '{}' data['john']['use…