4 ms·
> Integer math works exactly the way you would expect with no horrible surprises at all: >>> print [x / 3 for x in range(10)] [0, 0, 0, 1, 1, 1, 2, 2,
by rightbyte 6y ago
> Integer math works exactly the way you would expect with no horrible surprises at all:
>>> print [x / 3 for x in range(10)]
[0, 0, 0, 1, 1, 1, 2, 2, 2, 3]
Wont that print floats nowadays?
- pansa2 6y agoWithout parentheses, it won’t print anything.
- duckerude 6y agoAll the examples are things that no longer work in Python 3. Half of them are about functions like range() and .values() becoming lazy instead of returning simple lists. I think this is a genuine blow to ease of use, though it does get rid of performance pitfalls. The other half are about / always doing float division. But I think that's actually more intuitive for people who aren't already used to other programming languages, and it's much more predictable given that Python is dynamically typed and floats and ints sometimes get mixed up. It's also not awkward to work around, you can just write // instead of /. (Working around the other issue requires wrapping list() around things, which gets ugly very fast.)