python_cheat_sheet
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
python_cheat_sheet [2010/04/27 15:38] – ginko | python_cheat_sheet [2014/04/01 16:25] – ginko | ||
---|---|---|---|
Line 5: | Line 5: | ||
* Encodage <code python># -*- coding: utf-8 -*-</ | * Encodage <code python># -*- coding: utf-8 -*-</ | ||
* Commentaire <code python>#</ | * Commentaire <code python>#</ | ||
- | * Import <code python> | + | * Import <code python> |
* Arguments (passés au script) | * Arguments (passés au script) | ||
* Argv: (nécessite l' | * Argv: (nécessite l' | ||
* Il existe aussi une implémentation de getopt (//cf//. [[http:// | * Il existe aussi une implémentation de getopt (//cf//. [[http:// | ||
+ | ===== Packaging ===== | ||
+ | * Encapsulation pour librairie autonome <code python> | ||
+ | main()</ | ||
===== Variables ===== | ===== Variables ===== | ||
* Listes (mutable)< | * Listes (mutable)< | ||
+ | * Sets (mutable) fournit une interface implémentant les ensembles mathématiques (union, réunion, intersection, | ||
* Ajouter un élément en fin de liste: <code python> | * Ajouter un élément en fin de liste: <code python> | ||
* Tuple (immutable, mais plus performant) <code python> | * Tuple (immutable, mais plus performant) <code python> | ||
+ | * Matrices: installer et importer numpy ([[http:// | ||
* Casts | * Casts | ||
* String <code python> | * String <code python> | ||
* Integer <code python> | * Integer <code python> | ||
+ | * Tuple <code python> | ||
+ | * Liste <code python> | ||
* String délimité par ''''' | * String délimité par ''''' | ||
* Sur plusieurs lignes <code python>""" | * Sur plusieurs lignes <code python>""" | ||
Line 30: | Line 37: | ||
===== IO ===== | ===== IO ===== | ||
* Ouvrir un fichier <code python>#' | * Ouvrir un fichier <code python>#' | ||
- | fichier=open('/ | + | fichier=open('/ |
+ | # il faut alors fermer le fichier | ||
+ | # une métode qui referme le fichier proprement: | ||
+ | with open('/ | ||
+ | </ | ||
* '' | * '' | ||
* Sortie vers le shell: <code python> | * Sortie vers le shell: <code python> | ||
Line 40: | Line 51: | ||
instruction1 | instruction1 | ||
instruction2</ | instruction2</ | ||
- | * Opérateur '' | + | * Opérateur '' |
instruction</ | instruction</ | ||
instruction</ | instruction</ | ||
Line 73: | Line 84: | ||
* Classe: <code python> | * Classe: <code python> | ||
* Fonction: <code python> | * Fonction: <code python> | ||
+ | * Expansion des arguments dans un appel de fonction:< | ||
+ | function_name(*args) | ||
+ | kwargs = {' | ||
+ | function_name(**kwargs)</ | ||
+ | * Fonction anonyme (jettable, pour usage unique):< | ||
* Test: <code python> | * Test: <code python> | ||
python_cheat_sheet.txt · Last modified: 2015/01/02 13:03 by ginko