Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is the number 0 = true and is greater than 1 = false?

Asked by 4 years ago

I saw this "print(not 0)" and the output is "false".

So that makes 0 = true right , because not 0 = false or not true = false.

0 = true.

1 and above = false.

Am I right?

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Logical operators consider false and nil as false and anything else as true. This means when you apply a logical operator to anything it will equate any value that isn't false or nil as true. The "not" operator you're using returns the opposite of what the value given was equated to. Since it was 0 it was equated to true, and the "not" operator will equate it to false since it returns the opposite.

This goes for all values other than false or nil so it could be 1,2,3,4,5...n and it will still return false if you insert the not operator in front of the value.

However something like so

print(not false)

Will return true since true is the opposite of false.

For more reading on this topic, I recommend this.

Ad

Answer this question