Basic Python Basics Tutorial-Basics of Python expression

Source: Internet
Author: User
Tags logical operators

An expression

The expression is a combination of numbers, operators, numbers, parentheses, free variables, and constraint variables that can be used to derive a meaningful permutation of the values, so that it is usually composed of operands and operators, and if there are operands before and after operators, we call these operators the binocular operator, such as addition, subtraction, modulo, Operators, such as assignment operations, are both double-sided operators. If the operator has either an operand in front or an operand behind it, we call this operator a single-mesh operator, such as C + +,-and minus operations are all single-mesh operators, whereas the single-mesh operators in Python are relatively small in number.

An arithmetic expression

The common arithmetic operation expressions are composed of subtraction, modulus-taking, negative and power-square (* *) operators.

>>> x = 12>>> y = 13>>> z = 2>>> su = x + y>>> sm = x-y>>> sc = x * y>>> sd = x/y>>> sq = x% y>>> SF =-x>>> XZ = x * * z>>> print Su,sm,sc,s D,sq,sf,xz25-1 156 0 12-12 144

The arithmetic operation is relatively simple, the 10th line in the top statement needs to pay attention to the power square (* *) operator, X (* *) y means xy.

Relational expressions

A relational expression is actually a Boolean expression, a simple Boolean expression with only true (1) and False (0) two values, a slightly more complex Boolean expression is an expression consisting of a comparison operator greater than, less than, equal to, and so on, and the result of the expression is only true (1) and False (0) A value of two. The comparison operators used to build Boolean expressions are: Greater than >, less than <, equals = =, greater than or equal to >=, less than or equal to <=, not equal to! = and so on.

>>>4 = = 4true>>>4! = 4false>>>4 < 5true>>>4 >= 3true>>> "A" < "B" True
Logical Expressions

With logical operators and , or, and not, several expressions can be combined into a more complex Boolean expression, and the logical and and is the meaning and The result of this complex Boolean representation is true for both before and after expressions, whereas logic or or means that there is a truth in or around the whole, and the function of logical non-not is that if the value of the expression behind it is true, The result is false, and The result is true if the expression that is behind the not evaluates to False.

>>> A = true>>> B = false>>> A and bfalse>>> a or btrue>>>not afalse>>& Gt A and (not B) True


This article is from the "Python Training Zhipu Education" blog, so be sure to keep this source http://jeapedu.blog.51cto.com/7878264/1617076

Basic Python Basics Tutorial-Basics of Python expression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.