Python of arithmetic operators, comparison, assignment operator

What is the operator? As a simple example of 4 + 1 = 5. Example, 1 and 4 are called operands, "+" and "=" operator is called.
Operators used in the work are the following: arithmetic operators, comparison (relationship) operators, assignment operators, logical operators, members of the operators, the identity of the operator.

Arithmetic Operators
Operator Description

  • plus
  • Less
  • Multiply
    / divide
    % modulus - Returns the remainder of the division
    ** exponentiation - Returns the power of y x
    // divisible - returns the quotient of the integer part
    we use addition, subtraction, multiplication, division, modulo exponentiation, etc. divisible operation, as shown in the following code:

A =. 5
B = 2
Print (A + B, End = '')
Print (B + A, End = '')
Print (A - B, End = '')
Print (B - A, End = '')
Print (A B, End = '')
Print (B
A, End = '')
Print (A / B, End = '')
Print (B / A, End = '')
Print (A% B, End = '')
Print (B% A, End = '')
Print (A B, End = '')
Print (B
A, End = '')
Print (A // B, End = '')
Print (B / / a, end = '')
above will output the following:

7 7 3 -3 10 10 2.5 0.4 1 2 25 32 2 0

Comparison (relationship) Operators
Operator Description
== equal
! = Not equal

Greater than
<Less than
= greater than or equal
<= Less than or equal
we use equal, not equal, greater than, less than, greater than or equal taken, like less operation, as shown in the following code:

. 5 = A
B = 2
C. 1 =
D = 0
Print (A == B, End = '')
Print ((A! = B), End = '')
Print ((A> B), End = '' )
Print ((A <B), End = '')
Print ((A> = B), End = '')
Print ((A <= B), End = '')
Print ((BOOL (A)) , End = '')
Print ((BOOL (B)), End = '')
Print ((BOOL (D)), End = '')
above will output the following:

False True True False True False True True False

The results output from the comparison operation is Boolean (BOOL), only a Boolean True, False two kinds of value, either a True or a False, in Python, can be directly used True, False Boolean value indicating (Python for capitalization sensitive, note the case). Through the above we can see that only when the value is 0, bool type is False, the rest are to True. But in fact is not the case, also returns empty when the value False, as shown in the following code:

Print ((BOOL ([])), End = '')
Print ((BOOL ({})), End = '')
Print ((BOOL (())), End = '')
above will output the following content:

False False False

Assignment operators
Operator Description Examples
= assignment operator C = a + b a + b of the computation result assigned C
+ = addition assignment operator is equivalent to c + = a A + C = C
- = subtraction assignment operator c - = a is equivalent to CA = C *
= multiplication assignment operator is equivalent to c = a CA = C
/ division assignment operator = c / = a is equivalent to C = C / A
% = modulo assignment operator is equivalent to c% = a% C A = C
** exponentiation assignment operator = c = a is equivalent to CA = C
// = divisible taken assignment operator is equivalent to c // = a c = c / / a
we use the assignment operator calculates the above, the following code:

a = 5
b = 2

A + B = C
Print ( "C value:", c)

= A + B
Print ( "B value:", b)

= A * B
Print ( "B value:", b)

B / A =
Print ( "B value:", b)

% A = B
Print ( "B value:", b)

** A = B
Print ( "B value:", b)

= A // B
Print ( "B value:", b)
above will output the following:

c values:. 7
B values:. 7
B value: 35
B value: 7.0
B value: 2.0
B value: 32.0
B value: 6.0

It turns out that the output value of b has been changed. This is because the code is executed from top to bottom follow the principle, and b has been involved in operations, the value of b will always change.

Welcome attention to micro-channel public number: Wang software testing. Software testing exchange group: 809 111 560

Guess you like

Origin blog.51cto.com/14421641/2415252