python basis - basic operators

Arithmetic operators

Maths

a=87 b=5

 + Addition ---> adding two values
Liezi

a+b=92

 - subtraction ---> subtract two values
Liezi

a-b=82

 * Multiplication ---> value multiplied by two
Liezi

a*b=435

 / Division ---> value divided by two
Liezi

a/b=17.4

 // division floor (rounded) ---> take two values divided by the integer part
Liezi

a//b=17

 % Remainder Method ---> take two values of the remainder after dividing portion
Liezi

a%b=2


Comparison Operators

  == determines whether or equal
  ! = Not equal determines whether
  <determines whether less than
  > greater than determines whether


Assignment Operators

  = Simple assignment operator

c = a + b

Use the following assignment operator to use the assignment operator, there are times when a large number of times, particularly notable list of data types, it is not a simple increase, but re-opened up an address rebuild, so the emphasis !!!! !
-> use the assignment operator to use the assignment operator !!!!!

  - = subtraction assignment operator

c - = b is equivalent to c = a - b

  Addition assignment operator + =

c + = b is equivalent to c = c + b

  * = Multiplication assignment operator

C = B = C equivalent to C B

  / = Division assignment operator

c / = b is equivalent to c = c / b

  % = Modulo assignment operator

c% = b is equivalent to c = c% b

  ** exponentiation assignment operator =

C = B = C equivalent to C B

  // = rounding assignment operator

c // = b is equivalent to c = c // b


Logical Operators

From left to right way to find logical operators, logical operators found to the left, the left set up, go find the right logical operators
  and and

x and y -> is true only if the whole is true, otherwise it is false, even if only a false, but also for false

  or 或

x or y -> If there is a is true, then the whole it is true

  not negated

not x -> if x is true, false, if x is false, then true


Identity operator

Identity operator used to compare two of the memory cells.
is ---> Analyzing two identifiers are not referenced from an object
is not ---> Analyzing identifier is not referenced from two different objects
difference and is the ==: is for determining whether two object reference variables for the same (whether or not in the same memory space), == reference variable for determining the value are equal.

x = 257
y = x
z = 257

print(f'x is y:{x is y}')
print(f'x == y:{x == y}')

print(f'x is z:{x is z}')
print(f'x == z:{x == z}')

# 输出结果
# x is y:True
# x == y:True
# x is z:False
# x == z:True

python operator precedence

python operator precedence in mathematics equivalent of the first count and then count addition and subtraction multiplication and division, but this is silly high priority of your brackets on the line ...
To work! practical application () it is necessary to Oh! !!!

Guess you like

Origin www.cnblogs.com/suren-apan/p/11374629.html