Chapter III Python Operators

1. The arithmetic operators

Operators description Examples
+ Plus - two objects are added a + b output 31
- Save - to give a number to another number or a negative number by subtracting a - b output
* By - multiplying two numbers or returns the string to be repeated several times a a * b output
/ In addition - x divided by y b / a output
% Modulo - returns the remainder of division b% a output
** Power - Returns x to the power of y to power a ** b
// Take divisible - close to the rounded down integer divisor >>> 9//2 4 >>> -9//2 -5
  1. as long python is in quotation marks ( "content" or "content") is due to a string
  2. String +: string concatenation, and the string concatenation string only
  3. String *: strings and numbers are multiplied

2. Boolean operators

Operators Logical expression description Examples
and x and y Boolean "and" - if x is False, x and y returns False, else it returns evaluation of y. 1) If a return value of a is equal to 0
2) If a return value of b is not equal to 0
or x or y Boolean "or" - If x is True, it returns the value of x, otherwise it returns evaluation of y. 1) if x is 0 y return value
2) if x is not 0 returns the value of x
not not x Boolean "NOT" - If x is True, it returns False. If x is False, it returns True. not (a and b) returns False

3. assignment operator

Operators description Examples
= Simple assignment operator c = a + b a + b is the assignment of the operation result c
+= Addition assignment operator c + = a is equivalent to c = c + a
-= Subtraction assignment operator c - = a is equivalent to c = c - a
*= Multiplication assignment operator C = C = A is equivalent to C A
/= Division assignment operator c / = a is equivalent to c = c / a
%= Modulo assignment operator c% = a is equivalent to c = c% a
**= Power assignment operator C = C = A is equivalent to C A
//= Assignment operator take divisible c // = a is equivalent to c = c // a

4. Comparison Operators

Operators description
== Equal - compare objects for equality
!= It is not equal to - compare whether two objects are not equal
> Greater than - Returns whether x is greater than y
< Less than - Returns x is less than y. All comparison operators return 1 for true, 0 for false returns. True and False, respectively, which is equivalent to the special variables. Note the capitalization of these variable names.
>= Not less than - equal Returns whether x is greater than y.
<= Or less - Returns whether x is less than or equal y.

The logical operators:

Operators Logical expression description
and x and y Boolean "and" - if x is False, x and y returns False, else it returns evaluation of y.
or x or y Boolean "or" - If x is True, it returns the value of x, otherwise it returns evaluation of y.
not not x Boolean "NOT" - If x is True, it returns False. If x is False, it returns True.
  • True (True) or false (False)

    1. And (and):

      1) If a return is equal to a value of 0

      2) If a return is not equal to 0 the value of b

    2. 或(or):

      1) if x is 0 y return value

      2) if x is not 0 returns the value of x

    3. Non (not)

      1) negated

6. member operator

Operators description Examples
in If you find the value returned True, False otherwise specified sequence. x In y sequence returns True if x in y sequence.
not in If the value is not found in the specified sequence returns True, otherwise False. x is not y sequence, if x is not the sequence returns True y.

7. The identity of the operator

Means for storing the identity of the operator to compare two objects

Operators description Examples
is is two identifiers are determined from a reference to an object is not the y-IS the X- , similar to the above mentioned id (the X-) == the above mentioned id (the y-) , if the reference is to the same object returns True, otherwise False
is not is determined is not the identifier is not referenced from two different objects x is not y , 类似 id(a) != id(b)。如果引用的不是同一个对象则返回结果 True,否则返回 False。

Guess you like

Origin www.cnblogs.com/CrownYP/p/10988213.html