python中[无]和[]之间有什么区别? [英] what is difference between [None] and [] in python?
本文介绍了python中[无]和[]之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为[无]与[]相同,但是在我的测试中,也许有些东西...
I think [None] is same as [], but in my test , maybe there is something...
>>>print len([])
0
>>>print len([None])
1
我什么时候应该使用None?和[]
when should i use the None ? and []
和另一个有趣的问题
>>>c= []
>>>d= []
>>>print c is d
False
>>>a= 1
>>>b=1
print a is b
True
为什么空列表的ID授予不同?
why empty list's id granting that is different?
推荐答案
[]
是一个空列表
[无]
是具有一个元素的列表.那个元素是 None
[None]
is a list with one element. That one element is None
是
检查引用是否相等.如果两个对象通过 reference 引用同一对象,则 is
将返回true.
is
checks for reference equality. If both objects refer to the same object by reference then is
will return true.
a = []
b = a
a is [] #false
a is b #true
这篇关于python中[无]和[]之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文