4 ms·
C treats 0 as falsy so I would say that its more likely that Pythons behaviour is based on it - the Ruby and Clojure way has more to do with Scheme > That bein
by ufo 13y ago
C treats 0 as falsy so I would say that its more likely that Pythons behaviour is based on it - the Ruby and Clojure way has more to do with Scheme
> That being said, what's the point of having nil and false? Seems a bit redundant to me.
In some languages, like Common Lisp, nil and false are the same thing. However, it can be useful to separate the "this is a false value" from "this value does not exist", specially in a dynamically typed language.
For example, in Lua you get a "nil" if you access a table field that does not exist and you delete a table field if you store null to it. Before they added a separate boolean type, it was really annoying to work with boolean arrays because storing nil in the array would make it full of holes and would confuse most library functions.
- sireat 13y agoI do not remember C(at least C89) having false at all, so I do not see that Python would base its behaviour on C.
- ufo 13y agoBoth C and Python treat the number 0 as falsy if you use it in an if statement. On the other hand, Ruby and Clojure treat 0 as truthy if you pass it in an if statement if(0){ //Ruby and Clojure go here }else{ //C and Python go here }