Comment

Comment by wenc

Looks like the FAQ covers this question:

https://brython.info/static_doc/en/faq.html

Quote:

Q: why use the operator <= to build the tree of DOM elements? This is not pythonic!

A: Python has no built-in structure to manipulate trees, ie to add "child" or "sibling" nodes to a tree node. For these operations, functions can be used; the syntax proposed by Brython is to use operators: this is easier to type (no parenthesis) and more readable

To add a sibling node, the operator + is used.

To add a child, the operator <= was chosen for these reasons:

* it has the shape of a left arrow; note that Python function annotations use a new operator -> that was chosen for its arrow shape

* it looks like an augmented assignment because of the equal sign

* it can't be confused with "lesser or equal" because a line with document <= elt would be a no-op if it was "lesser or equal", which is always used in a condition or as the return value of a function

* we are so used to interpret the 2 signs < and = as "lesser or equal" that we forget that they are a convention for programming languages, to replace the real sign ≤

* in Python, <= is used as an operator for sets with a different meaning than "lesser or equal"

* the sign < is often used in computer science to mean something else than "lesser than": in Python and many other languages, << means left shift; in HTML tags are enclosed with < and >

* Python uses the same operator % for very different operations: modulo and string formatting

parent wenc 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton