gpt4 book ai didi

Python 错误绕过

转载 作者:行者123 更新时间:2023-11-28 21:25:28 25 4
gpt4 key购买 nike

对于多个帖子感到抱歉,我确实环顾四周,除了 try 方法之外找不到任何东西,这在某些情况下似乎很有用,但不是我的。

我正在寻找一种跳过错误的方法,因此控制台中不会显示任何内容,也不会停止脚本,只是一种绕过错误的方法。

即;

1. call a list
2. If list does not exist
3. create the list

最佳答案

在 Python 中,这是通过 try...except 实现的.在您的情况下,您可能想要捕获 NameError

try:
L[0]
except NameError:
L = ["Example",2]
L[0]

关于Python 错误绕过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14184440/

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