What is the difference between an expression and an expression using Python?

Possible duplicate:
Expression versus Expression

What is the difference between expression expression and in python?

I never thought about this question until I studied the Python generator, which said: " use output as an expression "

Also can you explain this question in the context of a Python generator that "uses output as an expression"?

+4
source share
3 answers

An expression can be evaluated to return a value. Any expression can also be used as an operator.

In other words, if you can write a = ... , then ... is an expression. So 2*3 and zip(x,y) are expressions.

Something like raise Exception is an expression, but not an expression: you cannot write a = (raise Exception) .

yield is an expression meaning that b = (yield a) is valid code in the generator. If you use the send() generator method, b set to the value you are passing.

+8
source

Expressions contain only identifiers, literals, and operators, where operators include arithmetic and Boolean operators, function call operators (), subscription operators [], etc. and can be reduced to some "value", which can be any Python object.

Statements , on the other hand, are all that may contain a line (or several lines) of Python code. Note that expressions are also operators.

Hope this helps you :)

+2
source

I would redo this:

  • expression is something - as said, it matters - and
  • instruction does something.

Of course, the problem with all abbreviations of this kind is that there is a reservation; an expression can still do something as part of its assessment. But in the end it still matters.

0
source

Source: https://habr.com/ru/post/1436356/


All Articles