Préambule
En 1989, le hollandais Guido van Rossum commence le développement du langage de programmation Python.
Python est un langage multiplateforme, c'est-à-dire disponible sur plusieurs architectures (compatible PC, tablettes, smartphones, ordinateur low cost Raspberry Pi...) et systèmes d'exploitation (Windows, Linux, Mac, Android...).
Le langage Python est gratuit, sous licence libre.
C'est un des langages informatiques les plus populaires avec C, C++, C#, Objective-C, Java, PHP, JavaScript, Delphi, Visual Basic, Ruby et Perl (liste non exhaustive).
Actuellement, Python en est à sa version 3.
Cependant, la version 2 est encore majoritairement utilisée.
Attention : Python 2 n'est pas compatible avec Python 3 !
Que peut-on faire avec Python ?
Beaucoup de choses !
- du calcul scientifique (librairie
NumPy
); - de l'intelligence artificielle (tensorflow);
- des graphiques (librairie
matplotlib
) - du traitement du son, de la synthèse vocale (librairie
eSpeak
) - du traitement d'image (librairie
PIL
), de la vision artificielle par caméra (frameworkSimpleCV
) - de la bio-informatique (librairie
Biopython
) - des applications avec interface graphique GUI (librairies
Tkinter
,PyQt
,wxPython
,PyGTK
...) - des jeux vidéo en 2D (librairie
Pygame
) - des applications multi-touch (framework
kivy
pour tablette et smartphone à écran tactile) - des applications Web (serveur Web
Zope
; frameworks WebFlask
,Django
) - interfacer des systèmes de gestion de base de données (librairie
MySQLdb
...) - des applications réseau (framework
Twisted
) - communiquer avec des ports série RS232 (librairie
PySerial
), en Bluetooth (librairiepybluez
)... - ...
Ils existent des dizaines de milliers de librairies qui sont disponibles sur le site officiel PyPI
pour nous aider à réaliser des milliards de choses.
Lorsque l'on apprend un nouveau langage de programmation. il est coutumiar d'écrire son premier programme pour afficher Hello world.
L'instruction en python qui affiche hello word est
print("Hello world")
Exécuter le programme ci-dessous et regarder le résultat dans la fenêtre de sortie Output.
- Écrit par : Richard GAUTHIER
- Affichages : 2483
"}, { "video" : "video1" } ], [ { "quiz" : "696" } ], [ {"title": "La planche à dessin (canvas) de Python", "text" : "Turtle est une librairie de python. Celle-ci permet de commander une tortue (une flèche) qui dessine!
"}, {"text":"Vous pouvez utiliser des fonctions ou instructions comme forward(distance) et left(angle) qui peuvent déplacer la tortue.
"}, {"text": "Avant de pouvoir utiliser la tortue, vous devez l'importer (import turtle) et exécuter les instructions."}, {"code": "import turtle\nforward(25)"}, {"text": "Modifier le programme pour dessiner 2 segments perpendiculaires de longueur 50."}, {"solution": "import turtle\nforward(50)\nleft(90)\nforward(50)"} ], [ {"html" : "701"}, {"code" : "print(\"Hello world\")\n print(\"Bonjour le monse\")"}, {"text" : "Exécuter le programme et corriger le bug."} ], [ {"html" : "702"}, {"code" : "import turtle"} ], [ {"html" : "703"}, {"code" : "import turtle"} ], [ {"text" : "
Exercice
Que diriez-vous d'un triangle? Dessinez un triangle équilatéral (angle 60° - côté 40).
"}, {"code" : "import turtle"} ], [ {"html" : "704"}, {"code" : "import turtle"} ], [ {"html" : "705"}, {"code" : "import turtle"} ] ]- Écrit par : Richard GAUTHIER
- Affichages : 2961
"}, { "video" : "video1" } ], [ { "quiz" : "696" } ], [ {"title": "La planche à dessin (canvas) de Python", "text" : "Turtle est une librairie de python. Celle-ci permet de commander une tortue (une flèche) qui dessine!
"}, {"text":"Vous pouvez utiliser des fonctions ou instructions comme forward(distance) et left(angle) qui peuvent déplacer la tortue.
"}, {"text": "Avant de pouvoir utiliser la tortue, vous devez l'importer (import turtle) et exécuter les instructions."}, {"code": "import turtle\nforward(25)"}, {"text": "Modifier le programme pour dessiner 2 segments perpendiculaires de longueur 50."}, {"solution": "import turtle\nforward(50)\nleft(90)\nforward(50)"} ], [ {"html" : "701"}, {"code" : "print(\"Hello world\")\n print(\"Bonjour le monse\")"}, {"text" : "Exécuter le programme et corriger le bug."} ], [ {"html" : "702"}, {"code" : "import turtle"} ], [ {"html" : "703"}, {"code" : "import turtle"} ], [ {"text" : "
Exercice
Que diriez-vous d'un triangle? Dessinez un triangle équilatéral (angle 60° - côté 40).
"}, {"code" : "import turtle"} ], [ {"html" : "704"}, {"code" : "import turtle"} ], [ {"html" : "705"}, {"code" : "import turtle"} ], [ { "quiz" : "696" } ] ]- Écrit par : Richard GAUTHIER
- Affichages : 1398
- Écrit par : Richard GAUTHIER
- Affichages : 2100
'); return this.body;//body; } /************************************ * traite les instructions du head ***********************************/ traiterInstHead(){ let nwc = "\\newcommand"; let cnt = "\\newcounter"; let lgnwc = nwc.length; let lgcnt = cnt.length; let posinwc = 1; let posicnt = 1; let boucle=12; posinwc = this.head.indexOf(nwc,this.posi+1); this.posi = posinwc+lgnwc; while (posinwc>0) { this.newcommand(); posinwc = this.head.indexOf(nwc,this.posi+1); this.posi = posinwc+lgnwc; }//fin while }//fin traiter /******************************************* * newcommand ****************************************/ newcommand() { let tagchercher = this.entreacco(); let tagnouveau = this.entreacco(); if(tagnouveau!="0") { this.head = this.remplace(this.head,tagchercher+"{",tagnouveau+"{",this.posi); if(this.paragraph==false) { this.body = this.remplace(this.body,tagchercher,tagnouveau,0); } else { this.paragraph=false; this.body = this.remplace(this.body,tagchercher,"
"+tagnouveau+"
",0); } this.posi--; //alert(this.posi+' '+tagchercher+' '+tagnouveau); } }//fin newcommand /******************************************* * recherche et remplace tag dans texte ****************************************/ remplace(texte:string,tagchercher:string,tagnouveau:string,positag=0):string{ positag = texte.indexOf(tagchercher,positag); while (positag>0) { texte = this.insert(texte,tagnouveau,positag,tagchercher.length); positag = texte.indexOf(tagchercher,positag+1); } return texte; } /******************************************* * renvoie la chaine entre les accolades ****************************************/ entreacco() { //let accoo = 0; //let accof = 0; let caract =""; let numacco = 0; let nonslash = true; let tag =""; let nbmax=50; do { caract = this.head[this.posi]; console.log(caract); if(caract=="\\") { nonslash = false; tag+=caract; } else if(caract=='{') { if(nonslash) { numacco++; if(numacco!=1) tag+=caract; } else { tag+=caract; nonslash=true; } } else if(caract=='}') { if(nonslash) {numacco--; if(numacco!=0) tag+=caract; } else { nonslash=true; tag+=caract; } } else if(caract==this.charReLigne) { numacco=-1; } else if(caract== '[') { numacco=-2; } else { tag+=caract; nonslash=true; } this.posi++; nbmax--; } while((numacco>0)&&(nbmax>0)); if(numacco==-2) { //recherche la balise paragraph this.paragraph=true; let balise = "\\paragraph{"; let posipara = this.head.indexOf(balise,this.posi); if (posipara>0) { let accof = this.head.indexOf('}',posipara+balise.length); tag = this.head.slice(posipara+balise.length,accof); numacco=0; //alert(tag); } } if(numacco==0) { return tag; } else { return "0"; } }//fin entreacco /************************************** * Remplacer les tag du body ******************************************/ nettoyerBody() { this.body = this.body.replace(/\\hfill\{([^\}]+)\}/g,'$1
'); this.body = this.body.replace(/\\LARGE/g,''); this.body = this.body.replace(/\\medskip/g,''); this.body = this.body.replace(/\\noindent/g,'
'); this.body = this.body.replace(/\\bf/g,''); this.body = this.body.replace(/\\section\{([^\}]+)\}/g,'
$1
'); this.body = this.body.replace(/\\subsection\{([^\}]+)\}/g,'$1
'); this.body = this.body.replace(/%[^\n]*(?=\n)/g,""); // remove LaTeX comments this.body = this.body.replace(/\\vspace[^\n]*(?=\n)/g,""); //remove comments this.body = this.body.replace(/\\hfill([^\}]+)\n/g,'$1
'); this.body = this.body.replace(/\\item\[(\w+)\]/g,"Ex
'); this.body = this.body.replace(/\\end\{EX\}/g,'
fin Ex
'); //this.effaceEntre2tag("\\begin{EX}","\\end{EX}"); //item ul ol //this.tagbeginend('\\begin{itemize}','
','\\end{itemize}','
'); //this.tagbeginend('\\begin{tabular}','
','\\end{tabular}','
'); this.body = this.body.replace(/\\begin\{itemize\}/g,''); this.body = this.body.replace(/\\end\{itemize\}/g,'
'); //tableau tabular //this.body = this.body.replace(/^\[[^\[]+\]/g,''); //this.tagbeginend('\\begin{tabular}','
' , '\\end{enumerate}' , ' |
aaaaa
"+this.body.slice(posifin); posideb = this.body.indexOf(tagdeb); } } longChaine(texte : string):number { return texte.length; } chargescript(){ var head = document.getElementsByTagName("head")[0], script; script = document.createElement("script"); script.type = "text/x-mathjax-config"; script[(window? "innerHTML" : "text")] = "MathJax.Hub.Config({\n" + " tex2jax: { inlineMath: [['$','$'], ['\\\\(','\\\\)']], processEscapes: true }\n" + ", TeX: { extensions: ['color.js'], equationNumbers: { autoNumber: 'AMS' } }\n" + "});" head.appendChild(script); script = document.createElement("script"); script.type = "text/javascript"; script.src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; //TeX-AMS_CHTML or edit previous line for any other cdn or local mathjax installation head.appendChild(script); } }
- Écrit par : Richard GAUTHIER
- Affichages : 1344