Skip to content Skip to sidebar Skip to footer

Why Does 4 > +4 Evaluate To False?

Why does the expression 4 >+4 return False? Example 4 > +4 #False

Solution 1:

Python does not have a unary numeric incrementation operator. +4 simply means 'apply the + operator to 4'. The unary + operator returns it's numeric value unchanged:

>>> +4
4

It exists to mirror the unary - operator, which returns the value negated:

>>> -4
-4

It does not mean 'add 1 to 4'.

If instead you meant to test for greater than or equality, then do so:

>>> 4 >= 4
True

> only means 'greater than' and clearly, 4 is not greater than 4.


Solution 2:

print +4 == 4

Output

True

+4 and 4 are the same. Thats why 4 > +4 returns False


Solution 3:

No number is larger than itself, so 4 is not greater than 4.


Note that the unary plus has nothing to do with it:

In [1]: 4 > +4
Out[1]: False

In [2]: 4 > 4
Out[2]: False

Post a Comment for "Why Does 4 > +4 Evaluate To False?"