Home  >  Article  >  Backend Development  >  How to write python expressions

How to write python expressions

(*-*)浩
(*-*)浩Original
2019-07-03 11:49:166820browse

An expression is a combination of values, variables and operators (or operators). A single value is an expression, and a single variable is an expression.

How to write python expressions

A typical expression generally consists of operators and operands/operating objects. (Recommended learning: Python video tutorial)

Operator: A symbol for performing operations on operands/operating objects.

Operator/operating object: the data processed by the operator.

Commonly used operators in conditional expressions are as follows:

(1) Arithmetic operators: - * / // % ** ~

(2) Relational operators: > < == != <> <= >=

(3) Test operators: in, not in, is, not is

(4) Logical operators: and, or, not

1. Arithmetic expressions and values ​​

The operation result of arithmetic expression is numeric type, and non-zero values ​​can be converted into It is regarded as True, and the zero value is regarded as False, that is, it can also be regarded as the result of Boolean operation.

2. Relational expressions and values ​​

Use two equal signs to compare whether the two operands are equal, the result will be True or False

 >>>3==3
 True
 >>>3==4
 False

Test expression
Member Test
Member test uses the cloud characters in and not in to return a logical value in the expression.

>>>a=[1,2,3]
>>>1 in a
True
>>>5 in a
False

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to write python expressions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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