语法中的Python字符串 - python

看到一段使用'str in str in str'语法的代码很奇怪,例如:

>>> 'test' in 'testtest' in 'testtesttest'
True
>>> 'test' in 'testtest' in 'tb3'
False
>>> 'test' in 'testtesta' in 'testtesttest'
False
>>> 'test' in ('testtest' in 'testtesttest')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    'test' in ('testtest' in 'testtesttest')
TypeError: argument of type 'bool' is not iterable

看起来“ in ... in ...”类似于“ <... <...”比较。但是,一个快速的谷歌并没有引导我找到官方答案。有什么帮助吗?

参考方案

Python documentation的官方答复:

comp_operator ::=  "<" | ">" | "==" | ">=" | "<=" | "!="
                   | "is" ["not"] | ["not"] "in"

in关键字是比较运算符。并且“比较可以任意链接”。请注意,这不限于“值比较”(>==等)。

有问题的代码检查每个元素是否都是链中下一项的子字符串。

Python pytz时区函数返回的时区为9分钟 - python

由于某些原因,我无法从以下代码中找出原因:>>> from pytz import timezone >>> timezone('America/Chicago') 我得到:<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD…

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python:检查是否存在维基百科文章 - python

我试图弄清楚如何检查Wikipedia文章是否存在。例如,https://en.wikipedia.org/wiki/Food 存在,但是https://en.wikipedia.org/wiki/Fod 不会,页面只是说:“维基百科没有此名称的文章。”谢谢! 参考方案 >>> import urllib >>> prin…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…

用大写字母拆分字符串,但忽略AAA Python Regex - python

我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…