kuzzooroo
kuzzooroo

Reputation: 7408

Python operators with other meanings (like the print chevron)

There are a number of questions on SO about Python's print chevron, which uses the same token as one of the bit-shift operators to send print's output somewhere other than stdout:

print >> sys.stderr, "foo"

From one of the answers:

The >> token is not actually an operator here; it's part of the syntax of the print statement, as documented here.

Are there other operators in Python 2 that also perform non-operator functions? What about Python 3 (in which the print chevron is gone)?

Upvotes: 2

Views: 1632

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799110

As shown in the grammar, only >>, * (positional expansion), and ** (keyword expansion) have non-operator meanings. Python 3.x (as of 3.4.x) retains the last two, and adds none. Python 3.5 will add a matrix multiplication operator (@) as well as its augmented assignment (@=).

Upvotes: 3

Related Questions