4 ms·
$python Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 >>> True + True 2 >>> okay... python3 Python 3.4.2 (default, Oct 8
by b0rsuk 9y ago
$python
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
>>> True + True
2
>>>
okay...
python3
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> True + True
2
>>>
I'm going to try this in Rust.
- Ygg2 9y ago> I'm going to try this in Rust. https://play.integer32.com/?gist=4c95f461e58727607c4b1c2c569af913&version=stable https://play.integer32.com/?gist=4c95f461e58727607c4b1c2c569... error[E0369]: binary operation `+` cannot be applied to type `bool` --> src/main.rs:5:13 | 5 | let x = true + true; | ^^^^^^^^^^^ | = note: an implementation of `std::ops::Add` might be missing for `bool`
- masklinn 9y ago> = note: an implementation of `std::ops::Add` might be missing for `bool` Incidentally you can not provide one, because implementing a trait on a type currently requires that either the trait or the type be local to the current crate: = note: the impl does not reference any types defined in this crate = note: define and implement a trait or new type instead
- akubera 9y agoWorks in C++: https://godbolt.org/g/bfM2zq https://godbolt.org/g/bfM2zq Does not compile in rust: https://godbolt.org/g/GTHM83 https://godbolt.org/g/GTHM83
- masklinn 9y agoI prefer `5 < {}` (fixed in Python 3).
- b0rsuk 9y agoI get the kick out of: True, False = False, True # fixed in Python3
- achanda358 9y agoThat's probably because $ python >>> int(True) 1 >>> int(False) 0
- masklinn 9y agoNo, that's because (for historical reasons of booleans having only been added in Python 2.3[0]) >>> issubclass(bool, int) True >>> True == 1 True >>> False == 0 True [0] https://www.python.org/dev/peps/pep-0285/ https://www.python.org/dev/peps/pep-0285/
- kbp 9y agoThat doesn't explain why, because there's no implicit conversion to int when adding things, eg: >>> s = '12' >>> int(s) 12 >>> s + s '1212'