Author: Kython Source: https://www.cnblogs.com/but-python/ welcome to reprint, please keep this statement. Thank you!
Last time, we try to use Python to calculate the 1 + 1
Find Python much like a calculator
This is not surprising, there are computers and calculators name "computing" word
Calculate the strengths of both should be
The computer can be seen as the enhanced version of the calculator
That we might like to use it as a calculator with Python
Try to do something we are familiar with math
No matter what your level of mathematics which stage
As long as the title to realize that they will just fine
The focus here is not mathematics
But to learn to use Python
Warming: familiar operators in Python
"+ - × ÷" symbols, in the programming, also known as "operator"
Python in operator, and the calculator in the representation is slightly different, more abundant
First, the comparison table, knocked example in Python, familiar operators in Python
Operators | description | Examples |
---|---|---|
+ | plus | >>> 5+4 9 |
- | Less | >>> 5-4 1 |
* | Multiply | >>> 5*4 20 |
/ | except | >>> 5/4 1.25 |
% | Modulo (the number of remainder) | 7% 3 >>> 1 (7 2 I is equal to 1 divided by 3) |
** | Power (square, cube, n-th power root) | >>> 2 ** 3 . 8 (the cube of 2) |
// | Divisible - integer part of the quotient ( rounded down ) | >>> 9//2 4 >>> -9//2 -5 |
Fledgling: third grade hybrid operation
Note: bracketed still apply in Python, but be careful in the English input method
Example 1. (21 ÷ 3 + 33) × 2
>>> (21/3+33)*2 80.0
Example 2. 4 × (36 ÷ 6 + 5)
>>> 4*(36/6+5)
44.0