python中数组为空怎么表示

如题所述

如果问题是给变量赋值为空数组:

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

第3个回答  2016-07-20

在 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'

本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网