False / True / O / 1 not equals !!!
Posted: Mon Jul 20, 2020 4:30 am
Hello,
Does somebody have an idea to explain that :
There is an embarrassing difference beetween Python and microPython :
========= and ==========
===================
In the same way
:
I think it is because the conditionnal expression if ... use int or boolean types to test if the expression is True/False or Null/not Null
but an int is not a boolean therefore 0 is not equal at False ...
Does somebody have an idea to explain that :
There is an embarrassing difference beetween Python and microPython :
Code: Select all
MicroPython v1.12-120-g4ab8bee82 on 2020-02-02; ESP32 module with ESP32
>>> False == 0
False
>>> True == 1
False
Code: Select all
Python 3.7.2 (/usr/local/bin/python3.7)
>>> False == 0
True
>>> True == 1
True
In the same way

Code: Select all
MicroPython v1.12-120-g4ab8bee82 on 2020-02-02; ESP32 module with ESP32
>>> a = False
>>> if a :
print ("Not nul or True")
else :
print("Nul or False")
Nul or False
>>> a = 0
>>> if a :
print ("Not nul or True")
else :
print("Nul or False")
Nul or False
>>> a == False
False
but an int is not a boolean therefore 0 is not equal at False ...