Python basis - arithmetic rule between different types of

We generally will not numeric type of data and a Boolean type of data operations, nor will the string types of data types and Boolean operations, this made no sense.

We need to borrow provided by Python arithmetic operators to complete the operation between variables, Python offers two:  arithmetic operators and compound assignment operators .

  • Arithmetic Operators
Operators description Examples
+ plus 10 + 20 = 30
- Less 10 - 20 = -10
* Multiply 10 * 20 = 200
/ except 10 / 20 = 0.5
// Take divisible (Supplier) 2 9 // output portion 4 to return the integer division
% Take the remainder Returns the division remainder = 1 2 9%
** power Also known as power, power, 2 3 = 8 **
  • Compound assignment operators
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 = A is equivalent to C  A
/= Division assignment operator c / = a is equivalent to c = c / a
//= Assignment operator take divisible c // = a is equivalent to c = c // a
%= Take  modulus  (remainder) assignment operator c% = a is equivalent to c = c% a
**= Power assignment operator c ** = a is equivalent to c = c ** a

note:

  1. All operations can be carried out between the digital and digital

  2. Only multiplication between numbers and strings.

  3. Only addition operations may be performed between the strings and string.


Guess you like

Origin blog.51cto.com/14163835/2423042