Python中判断list是否为空有以下两种方式:

方式一:

1 list_temp = []
2 if len(list_temp):
3     # 存在值即为真
4 else:
5     # list_temp是空的

方式二:

1 list_temp = []
2 if list_temp:
3     # 存在值即为真
4 else:
5     # list_temp是空的

以上两种方法均可以判断出 list_temp 列表是否是空列表,第二个方法要优于第一个方法,在Python中,False,0,'',[],{},()都可以视为假。

 

转载自:https://www.cnblogs.com/AiyaFocus/p/AiyaFocus.html

相关文章:

  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2021-07-23
猜你喜欢
  • 2021-10-07
  • 2022-02-06
  • 2022-01-06
  • 2022-01-01
  • 2022-12-23
  • 2021-11-06
相关资源
相似解决方案