None 是什么对象?这个问题真的太抽象了
空对象?
是全局对象。。。。。。(type, int, str, list, dict, set……在面向对象编程的世界里:万物皆对象)
>>> a = None
>>> type(a)
<type 'NoneType'>
>>>
>>> dir(a)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
>>>
>>> id(None)
4442812056
>>>
>>> a == 0
False
>>> a == ""
False
>>> class A(object):
... a = 1
... b = 2
...
>>>
>>> c = A()
>>> c = None # None 可以赋值,但null不能,也不能在python中使用
None 存在的意义可能是方法传参的默认值,也可能是if判断的条件。
def modelformset_factory(model, form=ModelForm, formfield_callback=None, formset=BaseModelFormSet, extra=1, can_delete=False, can_order=False, max_num=None, fields=None, exclude=None, widgets=None, validate_max=False, localized_fields=None, labels=None, help_texts=None, error_messages=None, min_num=None, validate_min=False, field_classes=None)
if a == None:
...
而Null在python中是不存在的,其实我简单最多的是跟数据库相关,这个值可以为null,所以个人认为None的作用更偏向于对象,null的作用更偏向于值。