Monday 22 April 2024

Python3 comparison operators

Meditate on this 🙏

'foo' is 'foo'
True

'foo' == 'foo'
True

'foo' is 'foo2'[:-1]
False

'foo' == 'foo2'[:-1]
True

'foo' is 'Foo'.lower()
False

'foo' == 'Foo'.lower()
True

0 == 0.0
True

0 is 0.0
False

0 is False
False

0 == False
True

not 0
True

Thanks to Joe Hornsby for providing these excellent examples.

No comments:

Post a Comment