Python判断list是否为空
1年前 • 659次点击 • 来自 其他
标签: Python
Python中判断list是否为空有以下两种方式:
方式一:
list_temp = []
if len(list_temp):
# 存在值即为真
else:
# list_temp是空的
方式二:
list_temp = []
if list_temp:
# 存在值即为真
else:
# list_temp是空的
第二个方法要优于第一个方法,在Python中,False,0,'',[],{},()都可以视为假。