(解决)如何使循环更轻松,然后只是更改Python中的循环编号

发布于 2025-02-07 03:07:59 字数 1401 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海夕 2025-02-14 03:07:59

我不知道这是否是您要搜索的,您可以做:

for i in range(1, loops_count + 1):
    browser.execute_script(f"arguments[{i}].scrollTop = arguments[{i}].scrollHeight", followers_ul)
                    

将f“ {variable}”添加到字符串中是一种简单的方法,即使具有变量的字符串。
在这种情况下,它将在字符串中替换为i循环计数。
如果不是这样,您能确定您的问题吗?

I don't know if it's what you're searching, you can do :

for i in range(1, loops_count + 1):
    browser.execute_script(f"arguments[{i}].scrollTop = arguments[{i}].scrollHeight", followers_ul)
                    

Adding f"{variable}" to a string is a simple way to have a string with variable.
In this case, it will replace in the string the i the loop count.
If it's not that, could you precise your question ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文