Introduction and usage of Python operators

Operators
1.1 Concepts
of Operators • Operators are used to perform program code operations and operate on more than one operand item. For example: 2 + 3, the operands are 2 and 3, and the operator is "+"

1.2 Classification of
operators • Arithmetic operators
• Assignment operators
• Comparison operators (relational operators)
• Logical operators
• Conditional operators (ternary operators)

2. Arithmetic operator operator
expression usage
addition operator + find the sum of two numbers
subtraction operator-find the difference between two numbers
multiplication operator * find the product of two numbers
division operator / find the quotient of two numbers
The division operator // will only retain the integer bits after calculation, and will always return an integer
modulo operator% Find the
power of the remainder operator of the division of two numbers ** Find the power of a value
3. Assignment operator
The special way of copying operator

Examples of operator expressions The
addition assignment operator + = x + = 3 is equivalent to x = x + 3 The
subtraction assignment operator-= x-= 3 is equivalent to x = x-3 The
multiplication assignment operator * = x = 3 is equivalent to x = x 3
power assignment operator ** = x ** = 3 is equivalent to x = x ** 3
division assignment operator / = x / = 3 is equivalent to x = x / 3
integer division assignment operator // = x // = 3 is equivalent to x = x // 3
modulo assignment operator% = x% = 3 is equivalent to x = x% 3
4. Comparison
operator Comparison operator is used to compare the relationship between two values ​​and will always return A Boolean value. Returns True if the relationship holds, otherwise returns False

Operator usage
> Compare whether the left value is greater than the right value
> = Compare the left value is greater than or equal to the right value
<Compare the left value is less than the right value
<= Compare the left value is less than or equal to the right The value on the side
== Compare whether the values ​​of two objects are equal
! = Compare whether the values ​​of two objects are not equal
is Compare whether the two objects are the same object, compare the id of the objects
is not compare An object, compared with the id of the object

 


————————————————
Copyright Statement: This article is an original article by CSDN blogger "Lang ...", which follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and reprint This statement.
Original link: https://blog.csdn.net/a1085217638/article/details/105477561

Guess you like

Origin www.cnblogs.com/LQZ888/p/12698483.html