python_cheat_sheet
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python_cheat_sheet [2010/04/27 15:45] – ginko | python_cheat_sheet [2015/01/02 13:03] (current) – ginko | ||
---|---|---|---|
Line 9: | Line 9: | ||
* 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 31: | 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> | ||
* Prompt au shell: <code python> | * Prompt au shell: <code python> | ||
+ | Pour travavailler avec les chemins de fichiers : '' | ||
===== Structure de code ===== | ===== Structure de code ===== | ||
* Boucle '' | * Boucle '' | ||
Line 74: | Line 85: | ||
* 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