0
None and null?
In sololearner python's >other types> None it says None represent no value 0 or [] , same as NULL in other languages. But when I tried if ((None==0) or (None==[])): print ("true") there was no output for this hence both are unequal now I tried in C if(NULL==0){ printf("true"); } here I got true. so how NULL and None are equal and why None!=0 or None!=[]
2 Antworten
+ 5
NULL in C is literally defined as `(void*)0` so it makes sense that NULL == 0 because NULL is zero. In Python, None gets it's own type, NoneType, so it is an object made from a class, and makes sense that it isn't == 0.
It's more of a language design thing, every language handles their nulls differently. To me this shows that C types are very weak. In C, everything is just a number if you squint hard enough, Python has classes and all that.
I think Python is doing the right thing, None is certainly not an array. But C is all about performance and being low-level so it's behaviour makes sense too.
Some interesting nulls:
PHP's `null` is like you described, `null == []`
Javascript has two nulls, `null` and `undefined`
Haskell has `undefined`, but as soon as you even look at it, your program crashes
SQL's NULL is funny because there NULL != NULL
+ 1
woah....
Thanks for that one
and after NULL!=NULL this definitely None is not similar to other language's NULL xD