4 ms·
What do you think is better about Python’s syntax? I generally like modern JavaScript’s syntax. I always figured the appealing part about python is the very goo
by peanut_worm 5y ago
What do you think is better about Python’s syntax? I generally like modern JavaScript’s syntax. I always figured the appealing part about python is the very good standard library.
- jokoon 5y agoList comprehension, the indent syntax that makes it very readable, the builtin functions, globally everything. The philosophy of python is well described here: https://www.python.org/dev/peps/pep-0020/ https://www.python.org/dev/peps/pep-0020/ I especially likes this one: > There should be one-- and preferably only one --obvious way to do it. It's true that the standard library is good, but generally I do more things with basic python than the base of other languages. And honestly I've never understood how js prototypes work. Python just feels better. The syntax is less cluttered. That's a huge point of python.
- BiteCode_dev 5y ago- sequence[-1] - sequence[start:finish:step] - no need for "===" - try/except with specific exceptions - context managers - yield from - "in" on any iterable - raise from - every empty object is false, all other are true - spread work on all iterables, not just arrays - f"{2:03}", f"{2:.2f}" and f"{date:%m/%d/%Y}" - / and // - no need for variable declaration keywords - 0b1111 - "else" in loops - := makes for explicit assignation + comparison instead of a footgun - None instead of null + undefined - set literals - matmul operator - foo > bar > baz - sorting callback semantics - dunder methods for operator overriding - list, dict and set comprehension - generator expressions - byte literals - raise SystemExit() for clean script exit - raw strings - automatic string literal concatenation - positional/keyword only parameters - can use *args and **kwargs together, as opposed to spread - docstrings - typing is part of the language, no need for a transpiled dialect like typescript - "async for" and "async with" That's only what I come up on the fly, I'm pretty sure I can double the list. Then of course, do we consider builtin to be part of the stdlib, since it doesn't require any import? Because there is a load to say there. JS does have some nice stuff too though: - ? and ?? - futures are more ergonomic than coroutines and awaitable anyway - more powerful destructuration - regex literals
- WillDaSilva 5y agoWeakref finalizers can help with instance destruction in Python https://docs.python.org/3/library/weakref.html#weakref.finalize https://docs.python.org/3/library/weakref.html#weakref.final...