gpt4 book ai didi

linux - python + 循环转义

转载 作者:太空宇宙 更新时间:2023-11-04 12:36:08 26 4
gpt4 key购买 nike

在我的 linux 机器上我有 python 脚本,相关的行是:

        for cont in tmp:
allConts.append(cont[0])

如何更改添加规则 - 如果 cont 变量为 null,for 循环将转义执行 allConts.append(cont[0])?

最佳答案

使用if cont 确定cont 不是None 或空列表(python 的null):

for cont in tmp:
if cont:
allConts.append(cont[0])

关于linux - python + 循环转义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41740824/

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