VocabulairePythondebaseenL1Sciences-Automne2016 Cettefeuilleestleseuldocumentautorisélejourdel'examen.Elleneconcernequecequiaétéétudiédansle coursdeprogrammationenPython3de1èreannée.Avousdebiensaisirlasignificationdetouscesmots! Typesétudiésint,float,bool,str,list,tuple, set, dict Testdetypetype Ex: if type([2,5,3]) == list : ... Modules,onindiqueentrecrochetslesobjetslesplusimportés fractions[Fraction,gcd] math[pi,sqrt,factorial,sin,log,...] random[randint], turtle[*] time[time,sleep] polycreux[*] os[...] tkinter[*] Importations from ... import ... import ... from ... import ... as ... Affichage(lescrochetsindiquenticidesargumentsoptionnels) print(x,y,...,[sep=’ ’],[end=’\n’]) Opérateursconditionnelsand Egalité== or not != Intervallesd'entiers(itérateurs):range(n)range(a,b)range(a,b,s) NOMBRES+ - * % // / ** abs EXCEPTIONS(simples) try : ... except : ... CHAÎNESDECARACTERES(str) + i*s len(s) in s[i] == int(s) str(n) bin(n) chr(i) ord(c) s.count(s) s.index(s) s.isupper() s.islower() s.isalpha() s.isdigit() s.upper() s.lower() s.replace(old,new) s.split(sep=' ') L.join(s) LISTES(list) + i*L L.count(x) len(L) L.sort() in L[i] sorted(L) == L.pop(i) L.index(x) L.reverse() L.insert(i,x) in == L.append(x) L.extend(L1) TUPLES(tuple) + i*t len(t) t[i] t.index(x) t.count(x) POLYNOMESCREUX[[cn,en],...](modulepolycreux) poly0() mul(p,q) is_poly0() mul_ext(k,p) coef(p) valeur(p,x) degre(p) fpoly(p) <= len(E) add(p,q) sub(p,q) ENSEMBLES(set) in & | - < == E.add(x) E.pop() DICTIONNAIRES(dict) len(d) in d[k] d.update(d1) d.keys() d.values() E.remove(x) COMPREHENSIONS(deliste,d'ensemble,dedictionnaire) [f(x) for x in <iterable>] [f(x) for x in <iterable> if test(x)] {f(x) for x in <iterable>} {f(x) for x in <iterable> if test(x)} {f(x):g(x) for x in <iterable>} {f(x):g(x) for x in <iterable> if test(x)} sum(f(x) for x in <iterable> if test(x)) # f(x) doit être un nombre ! Itérable : un objet sur lequel on peut faire une boucle for. Ex: range, str, list, set, dict Contre-Ex: int, float FICHIERSDETEXTE f.read() f.readline() f.readlines() for ligne in f_in : ... f_in = open(s,'r',encoding='utf-8') f.write(s) f.writelines(L) f_out = open(s,′𝑤′,encoding='utf-8') ′𝑎′ f.close() GRAPHISMETORTUE(moduleturtle) forward(d) goto(pt) dot(diam) back(d) goto(x,y) reset() left(a°) right(a°) pos() heading() tracer(bool) down() up() setheading(a°) ht() st() pencolor(s) PROGRAMMATIONPAROBJETS Dans le constructeur __init__ ou dans une méthode, self représente l'objet courant. class __init__(self,...) __repr__(self) __add__(self,obj) __mul__(self,obj)