如题所述
如果问题是给变量赋值为空数组:
ary = []如果问题是如何判断变量数组为空:
ary = []if len(ary) == 0:
print('数组为空')
温馨提示:答案为网友推荐,仅供参考
第1个回答 2018-03-30
在 Python 中,最常用的数组是 list
list_a = [1,2,3]
list_void = []
print len(list_a) # 3
print len(list_void) # 0
# When list is void
if len(list_void): print 'list is not void'
else: print 'list is void'
# or more directly
if list_a: print 'list_a is not void
if not list_void: print 'list_void is void'
第2个回答 2016-07-20
list_ = []
print not list_ ,list_ is None,list_ == None
print not list_ ,list_ is None,list_ == None
第3个回答 2016-07-20
在 Python 中,最常用的数组是 list
list_void = []
print len(list_a) # 3
print len(list_void) # 0
# When list is void
if len(list_void): print 'list is not void'
else: print 'list is void'
# or more directly
if list_a: print 'list_a is not void'
if not list_void: print 'list_void is void'本回答被提问者采纳