在python中删除列表后是否存在列表是否存在的方法
我正在尝试查看是否有一种方法可以查看列表在列表上执行DEL命令后是否被删除,
del users
if bool(users):
print("exist")
上面提到了我尝试的方法之一。但是对于每一个,我都会有一个错误 -
unboundlocalerror:分配前引用的本地变量'用户
,它无法引用它,但是我想知道是否有办法(一种内置的方法),我可以检查它是否已删除(不是空)
I'm trying to see if there's a way I can see if the list got deleted after doing del command on the list
del users
if bool(users):
print("exist")
One of the ways that I tried is mentioned above. But for each of these, I get an error-
UnboundLocalError: local variable 'users' referenced before assignment
Since the list is not present, it is unable to reference it but I wanted to know if there's a way(an in-built method) I can check if it got deleted( not empty)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用try-except语句来捕获错误:
You can use a try-except statement to catch the error: