Learn Python - 2 [Numbers]

in #python6 years ago

imageedit_4_9128275118.jpg
Every programming language has numbers which is a way to do math. Doing math with python is easy. First lets look what operators do we have and then we will see how to use this operators.

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • ** exponent
  • % remainder
  • < less- than
  • > greater- than
  • <= less- than- equal
  • >= greater- than- equal

What is integer: each item in this list [-infinity, ..., -3, -2, -1, 0, 1, 2, 3, ..., infinity] is an integer.
All the above operators are valid for integers.

>>> 25 + 30
55
>>> 7 - 2
5
>>> 4 % 2
0
>>> 2 ** 7
128
>>> 5 > 7
False
>>> 7 > 5
True
>>> print('Is it greater or equal?', 3 >= 9)
Is it greater or equal? False
>>> 1 - 5 + 4 % 2
-4

What is the order of operations?: Parentheses - Exponents - Multiplication - Division - Addition - Subtraction.

When we compute 2 + 3 * 4, 3 * 4 is computed first as the precedence of * is higher than + and then the result is added to 2.

>>> 2 + 3 * 4
14

Use parenthesis to specify the explicit groups.

 >>> (2 + 3) * 4
20

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 60826.65
ETH 2907.17
USDT 1.00
SBD 3.54