Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> animaux = "girafe tigre" >>> animaux 'girafe tigre' >>> len(animaux) 12 >>> ================================ RESTART ================================ >>> >>> example.py Traceback (most recent call last): File "", line 1, in example.py NameError: name 'example' is not defined >>> ================================ RESTART ================================ >>> >>> exemple.py Traceback (most recent call last): File "", line 1, in exemple.py NameError: name 'exemple' is not defined >>> ================================ RESTART ================================ >>> girafe tigre 12 >>> len(animaux) #longueur 12 >>> >>> >>> >>> >>> >>> animaux = "girafe tigre" >>> len(animaux) # longueur de la chaine 12 >>> animaux[4] # retourne le 4ieme element 'f' >>> pipo = "une" + "deux" # concatenation >>> pipo 'unedeux' >>> animaux[0:4] 'gira' >>> animaux[9:] 'gre' >>> animaux[:2] 'gi' >>> animaux[:-2] 'girafe tig' >>> >>> >>> >>> nom = "girafe" >>> nom.upper() 'GIRAFE' >>> nom.capi Traceback (most recent call last): File "", line 1, in nom.capi AttributeError: 'str' object has no attribute 'capi' >>> nom.capinom.capi Traceback (most recent call last): File "", line 1, in nom.capinom.capi AttributeError: 'str' object has no attribute 'capinom' >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> nom 'girafe' >>> >>> >>> >>> nom = "girafe" >>> nom.upper() 'GIRAFE' >>> nom.capitalize() 'Girafe' >>> animaux = "girafe tigre singe" >>> animaux.split() # decoupe ['girafe', 'tigre', 'singe'] >>> animaux = "girafe - tigre - singe" >>> animaux.split("-") # decoupe avec separateur ['girafe ', ' tigre ', ' singe'] >>> >>> >>> >>> >>> nom 'girafe' >>> >>> >>> >>> animal = "girafe" >>> animal.find('i') 1 >>> animal.find('ira') 1 >>> animal.find('afe') 3 >>> animal.find('tig') -1 >>> >>> animaux = "girafe tigre" >>> animaux.replace("tigre","singe") 'girafe singe' >>> animaux.replace("i","o") 'gorafe togre' >>> animaux.count("i") 2 >>> animaux.count("z") 0 >>> animaux.count("tigre") 1 >>> >>> separation = "-" >>> seq = ("a","b","c","d") >>> str.join(seq) Traceback (most recent call last): File "", line 1, in str.join(seq) TypeError: descriptor 'join' requires a 'str' object but received a 'tuple' >>> >>> sq Traceback (most recent call last): File "", line 1, in sq NameError: name 'sq' is not defined >>> seq ('a', 'b', 'c', 'd') >>> separation.join(seq) 'a-b-c-d' >>> >>> separation = "-" >>> seq = ("a","b","c","d") >>> separation.join(seq) SyntaxError: multiple statements found while compiling a single statement >>> >>> >>> >>> >>> >>> separation = "-" >>> seq = ("a","b","c","d") >>> separation.join(seq) SyntaxError: multiple statements found while compiling a single statement >>> >>> >>> >>> separation = "-" >>> seq = ("a","b","c","d") >>> separation.join(seq) 'a-b-c-d' >>> >>> >>> str = "0000000this is string example....wow!!!0000000" >>> str.strip( '0' ) 'this is string example....wow!!!' >>> >>> >>> >>> liste = [] >>> liste [] >>> liste = [1,2,3] >>> liste [1, 2, 3] >>> liste.append["ok"] Traceback (most recent call last): File "", line 1, in liste.append["ok"] TypeError: 'builtin_function_or_method' object is not subscriptable >>> >>> >>> >>> liste [1, 2, 3] >>> >>> >>> >>> >>> >>> liste = [] >>> liste [] >>> liste.append("ok") # ajouter un element >>> liste ['ok'] >>> liste[0] # afficher un item 'ok' >>> liste[0]= 464 # changer la valeur >>> liste [464] >>> liste = ["a", "b" ,"c" ,"d"] >>> liste ['a', 'b', 'c', 'd'] >>> liste.remove("b") >>> liste ['a', 'c', 'd'] >>> liste.reverse() >>> liste ['d', 'c', 'a'] >>> >>> >>> liste = ["a", "b" ,"c" ,"d", 125] >>> liste ['a', 'b', 'c', 'd', 125] >>> len(liste) # compter le nombre d'elements 5 >>> liste = ["a","a","a","b","c","c"] >>> liste.count("a") # compte le nombre d'occurence 3 >>> liste.index("b") # trouver l'index d'une occurence 3 >>> liste = [1, 10, 100, 250, 500] >>> liste[0] 1 >>> liste[-1] # Cherche la dernière occurence 500 >>> liste[-4:] # Affiche les 4 dernières occurrences [10, 100, 250, 500] >>> liste[:] # Affiche toutes les occurences SyntaxError: unexpected indent >>> liste[:] # Affiche toutes les occurences [1, 10, 100, 250, 500] >>> >>> >>> >>> >>> liste[:] # Affiche toutes les occurences SyntaxError: unexpected indent >>> liste[:] # Affiche toutes les occurences [1, 10, 100, 250, 500] >>> liste[2:4] = [69, 70] >>> liste [1, 10, 69, 70, 500] >>> liste[:] = [] # vide la liste >>> liste [] >>> liste [] >>> liste = [1, 10, 100, 250, 500] >>> del liste[1] # supprimer un entrée de la liste >>> liste [1, 100, 250, 500] >>> liste [1, 100, 250, 500] >>> >>> liste.index(250) 2 >>> >>> liste.index(250) # retourne la position dans la liste - l'index 2 >>> liste.insert(3,"toto") >>> liste [1, 100, 250, 'toto', 500] >>> >>> >>> tulpe=('a',2,[1,3]) >>> tulpe ('a', 2, [1, 3]) >>> >>> >>> d1 = {} >>> d1["nom"] = 3 >>> d1["taille"]= 185 >>> d1 {'nom': 3, 'taille': 185} >>> d2 = {"lili": 25, "coco": 123} >>> d2 {'coco': 123, 'lili': 25} >>> >>> >>> >>> tel = {'jack': 4098, 'paul': 4139} >>> tel['vincent']=7551 >>> tel {'vincent': 7551, 'paul': 4139, 'jack': 4098} >>> del tel['paul'] >>> tel {'vincent': 7551, 'jack': 4098} >>> tel['bob']=195 >>> tel {'vincent': 7551, 'jack': 4098, 'bob': 195} >>> tel.keys() dict_keys(['vincent', 'jack', 'bob']) >>> sorted(tel.keys()) ['bob', 'jack', 'vincent'] >>> >>> ================================ RESTART ================================ >>> >>> exemple Traceback (most recent call last): File "", line 1, in exemple NameError: name 'exemple' is not defined >>> exemple.py Traceback (most recent call last): File "", line 1, in exemple.py NameError: name 'exemple' is not defined >>> ================================ RESTART ================================ >>> >>> ================================ RESTART ================================ >>> Resultat: 13 et 40 >>> ================================ RESTART ================================ >>> Resultat: 13 et 40 >>> a.x 23 >>> a=toto() >>> a <__main__.toto object at 0x0000000003277B38> >>> ================================ RESTART ================================ >>> Resultat: 13 et 40 >>> z Traceback (most recent call last): File "", line 1, in z NameError: name 'z' is not defined >>> toto.z 6 >>> ================================ RESTART ================================ >>> Resultat: 13 et 40 >>> toto.lolo Traceback (most recent call last): File "", line 1, in toto.lolo AttributeError: type object 'toto' has no attribute 'lolo' >>> lolo Traceback (most recent call last): File "", line 1, in lolo NameError: name 'lolo' is not defined >>> a.lolo 125 >>> ================================ RESTART ================================ >>> Resultat: 13 et 40 28 42 >>> 1.9 1.9 >>> x= SyntaxError: invalid syntax >>> >>> >>> >>> x=[1,2,3] >>> x = x+8 Traceback (most recent call last): File "", line 1, in x = x+8 TypeError: can only concatenate list (not "int") to list >>> >>> >>> x = [1,2,3] >>> x = x + [5] >>> x [1, 2, 3, 5] >>> >>> >>> x [1, 2, 3, 5] >>> y=x >>> y [1, 2, 3, 5] >>> x[1]=55555 >>> y [1, 55555, 3, 5] >>> >>> >>> >>> >>> >>> NameError: name 'z' is not defined SyntaxError: invalid syntax >>> >>> >>> >>> x