Python expressions are a combination of values, variables and operators (or operators). A single value is an expression, and a single variable is an expression.
Operators and operands together form an expression. The operands can be represented by identifiers, such as a=3;b=2;c=a*b, and the expression is a python program The most common code
Python code consists of expressions and statements and is executed by the Python interpreter. (Recommended learning: Python video tutorial)
The main difference between them is that "expression" is a value, and its result must be a Python object. The result can be any object when the Python interpreter evaluates it. For example, 42, 1 2, int(‘123’), range(10), etc.
Priority of expressions
Expressions have priorities. The simplest ones are the mathematical calculations in our assignment operator: "0 * 1 2" and "0 1 * 2" "The results must be different. In "0 1 * 2", "1 * 2" is calculated first.
Of course, not only assignment operations have priority, but there are also priorities among various operators.
#在下面这个运算中,假设a、b、c都是ture值,因为and 的优先级大于 or ,所以最后结果是a# >>> a or b and c a #在下面这个运算中,假设a、b、c、d都是ture值# #因为 + 的优先级大于 and 大于 or ,所以最后结果是a + b的结果# >>> a + b or c and d a + b #用括号表现优先级就是:先运行a + b,再运行c or d 得到 d ,最后运行(a+b) or d# >>> (a + b) or (c and d) a + b
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of what is python expression. For more information, please follow other related articles on the PHP Chinese website!