what is python expression

(*-*)浩
Release: 2019-07-09 10:10:08
Original
21196 people have browsed it

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

what is python expression

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template