gpt4 book ai didi

python - 在 Python 3.3 中是否有一种漂亮的 yield 方法?

转载 作者:太空狗 更新时间:2023-10-30 02:21:31 25 4
gpt4 key购买 nike

有没有办法让这段代码更漂亮?

strong = li.find_all("strong")if strong:  yield li.find_all("strong")

我的意思是这样的:

strong = li.find_all("strong")yield li.find_all("strong") if strong

最佳答案

你会使用:

strong = li.find_all("strong")
if strong:
yield strong

而不是再次调用 find_all() (在 BeautifulSoup 中,它给出相同的结果,但再次)。 p>

没有“条件 yield ”。您可以使用 yield from 玩花样,但我建议您不要这样做。

关于python - 在 Python 3.3 中是否有一种漂亮的 yield 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15646733/

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