In [1]:
4+3
Out[1]:
7
In [2]:
4*3
Out[2]:
12
In [3]:
4**3     #puissance
Out[3]:
64
In [4]:
7/3
Out[4]:
2.3333333333333335
In [5]:
7//3   #quotient de la division euclidienne
Out[5]:
2
In [6]:
7%3    #reste de la division euclidienne
Out[6]:
1
In [7]:
round(7/3)    #arrondi à l'unité
Out[7]:
2
In [8]:
round(7/3,5)   #arrondi à 5 chiffres après la virgule
Out[8]:
2.33333
In [9]:
abs(-2.5)    #valeur absolue
Out[9]:
2.5

Racine carrée : il faut importer la commander sqrt présente dans le module math :

In [10]:
from math import sqrt
sqrt(2)
Out[10]:
1.4142135623730951
In [11]:
from math import floor
floor(2.35)    #partie entière
Out[11]:
2
In [12]:
floor(-2.35)
Out[12]:
-3

NB : on peut importer tout le module math d'un coup par : from math import *

Variables booléennes

In [13]:
3 == 2   #teste si 3 est égal à 2
Out[13]:
False
In [14]:
a = (5 == 2+3)
print(a)
type(a)
True
Out[14]:
bool
In [15]:
3 < 2
Out[15]:
False
In [16]:
3 >= 2
Out[16]:
True
In [17]:
not a
Out[17]:
False
In [ ]: