您在這裡

Expressions

23 二月, 2015 - 09:50

An expression is a combination of values, variables, and operators. A value all by itself is considered an expression, and so is a variable, so the following are all legal expressions (assuming that the variable x has been assigned a value):

17 xx + 17

If you type an expression in interactive mode, the interpreter evaluates it and displays the result:

>>> 1 + 12

But in a script, an expression all by itself doesn’t do anything! This is a common source of confusion for beginners.

Exercise 2.1 Type the following statements in the Python interpreter to see what they do:

5x = 5x + 1