Ceci est une ancienne révision du document !
Table des matières
Les types
entier ** (type *int*) comme 3 ou 42 **réel ** (type *float*) comme 2.4 ou 3.14159265 **liste ** (type *list*) comme [1, 2, 3, 12] **chaîne de caractères ** (type *str*) comme “bonjour” **booléen ** (type *bool*) comme True ou False <code> a = 10 b = 3 print(a, b) a, b = b, a print(a, b) </code> ===== Les entiers ===== *Les opérations utilisables sur les entiers sont:* <code> + addition - soustraction * multiplication // quotient de la division euclidienne % reste de la division euclidienne ** puissance </code> ===== Les flottants ===== *Sur les réels:*// // <code> + addition - soustraction * multiplication / division ** puissance </code> Vous pouvez entrer un float en mémoire en utilisant une notation classique (attention, le séparateur est un point pas une virgule) ex: C = 0.0010 On peut aussi utiliser une notation proche de ce que l'on a sur les calculatrices ex: G = 6.67e-11 ===== Les listes ===== <code> L = [1, 2, 3] </code> <code> vide = [ ] </code> <code> x = [1,2,3,4] print(x) x.append(5) print(x) </code> donne <code>[1, 2, 3, 4] [1, 2, 3, 4, 5] </code> <code> len(x) </code> donne <code> 5 </code> <code> L = [12, 42, 36, 17] print( L[2] ) </code> donne <code> 36 </code> <code> x = [12, 42, 36, 17] print( x ) x[ 2 ] = 15 print( x ) </code> donne <code>[12, 42, 36, 17] [12, 42, 15, 17] </code> <code> a = [1, 2, 3] b = [4, 5, 6] c = a + b print( c ) </code> donne <code>[1, 2, 3, 4, 5, 6] </code> <font 14px font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(240, 240, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;/monospace;;inherit;;rgb(0, 0, 0) font-family: monospace; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(240, 240, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;>[ 0 ] * 4</font> donne <font 14px font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(240, 240, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;/monospace;;inherit;;rgb(0, 0, 0) font-family: monospace; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(240, 240, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;>[0, 0, 0, 0]</font>
