4 ms·
Python is my favorite programming language because of its simplicity and ease of use. For example, working with lists in a REPL is easy: >>> print range(10)
by lwneal 6y ago
Python is my favorite programming language because of its simplicity and ease of use. For example, working with lists in a REPL is easy:
>>> print range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Integer math works exactly the way you would expect with no horrible surprises at all:
>>> print [x * 3 for x in range(10)]
[0, 3, 6, 9, 12, 15, 18, 21, 24, 27]
>>> print [x / 3 for x in range(10)]
[0, 0, 0, 1, 1, 1, 2, 2, 2, 3]
Python is great for little one-off tasks; say you want a color half the brightness of #308cfb
>>> hex(0x30 / 2)
'0x18'
>>> hex(0x8c / 2)
'0x46'
>>> hex(0xfb / 2)
'0x7d'
The built-in support for dictionaries and JSON parsing make data conversion easy:
>>> import json
>>> json.dumps({'foo': 42, 'bar': 132}.values())
'[42, 132]'
If there's one thing I love about Python, it's how easy and consistent it is. It sure is great that we've spent the last decade teaching Python to every scientist, academic, and hobbyist.
If there are two things I love about Python, it's that and the reliable, well-supported Python package manager.
- 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.)
- nooorofe 6y ago>>> print(range(10)) range(0, 10) >>>