-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodularite.html
176 lines (157 loc) · 8.47 KB
/
modularite.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="fr">
<!-- Meta-données -->
<head>
<meta charset="utf-8">
<title>Modularité - Cours - PythonMasterClass</title>
<link rel="icon" type="image/png" sizes="32x32" href="./images/icons/icon.png">
<link href="css/styles.css" rel="stylesheet" type="text/css">
<!-- Police du h1 -->
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@700&display=swap" rel="stylesheet">
<!-- CodeMirror -->
<link rel="stylesheet" href="plugin/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="plugin/codemirror/theme/monokai.css">
<script src="plugin/codemirror/lib/codemirror.js"></script>
<script src="plugin/codemirror/mode/python/python.js"></script>
</head>
<!-- Corps de la page -->
<body>
<!-- Haut de page -->
<header>
<!-- Logo -->
<a href="breviaire.html"><img src="images/logos/logo.png" alt="PythonMasterClass"></a>
<!-- Barre de navigation -->
<nav>
<a href="index.html">Accueil</a>
<a href="introduction.html" id="selected">Cours</a>
<a href="breviaire.html">Bréviaire</a>
<a href="contact.html">Contact</a>
</nav>
</header>
<!-- Contenue de la page -->
<main>
<section>
<div id="toph1"><h1>Modularité</h1></div>
<div id="sommaire">
<nav>
<span>Sommaire</span>
<a href="introduction.html">Introduction</a>
<a href="installation.html">Installation</a>
<a href="erreurs.html">Erreurs</a>
<a href="variables.html">Variables</a>
<a href="booleans.html">Booleans</a>
<a href="conditions.html">Conditions</a>
<a href="boucle_while.html">Boucle While</a>
<a href="boucle_for.html">Boucle for</a>
<a href="list_et_tuple.html">List et tuple</a>
<a href="dictionnaires.html">Dictionnaires</a>
<a href="fonctions.html">Fonctions</a>
<a href="lambda.html">Lambda</a>
<a href="itinerables.html">Itinérables</a>
<a href="yield.html">Yield</a>
<a href="modularite.html">Modularité</a>
<a href="class.html">Class</a>
<a href="methodes.html">Méthodes</a>
</nav>
</div>
<div id="with-sommaire">
<article>
<h2>Les modules extérieur</h2>
<p>
Il existe plein de modules comprenant des fonctions autour des mathématiquess
(<a href="https://docs.python.org/3/library/math.html?highlight=math">math</a>),
itinérable (<a href="https://docs.python.org/3/library/itertools.html">itertools</a>),
tableau à n dimantion (<a href="https://numpy.org/doc/stable/user/quickstart.html">numpy</a>)
ou bien permettant l'interaction avec l'os (<a href="https://docs.python.org/fr/3.9/library/os.html?highlight=os">os</a>)
ou le systeme (<a href="https://docs.python.org/fr/3.9/library/sys.html?highlight=sys">sys</a>).
</p>
<code>
import itertools
import numpy as np
from math import cos
from math import *
</code>
<p>
Tout d'abord il existe plusieurs façons d'importer des modules.
À la première ligne nous importons tout le module itertools,
à la deuxième ligne on import le module numpy en le renommant
via le mot-clé as permettant des racoursir l'écriture.
À la troisième ligne nous importons que la fonction cos
et nous n'auront donc plus à préciser le module lors de l'appel.
Pour la dernière ligne elle permet d'importer toutes
les fonctions d'un module sans avoir répété le module.
</p>
<code class="firstLineNumber5">
# parcours tous les tulpes possibles composé de 0123456789abcdef d'une longueur de 2
for chars in itertools.product("0123456789abcdef", repeat=2):
print("".join(chars))
# crée une matrice de 5x9
array = np.zeros((5, 9))
print(array)
# cosinus de 10
print(cos(10))
</code>
<p>
La puissance des modules est que vous n'avez pas refait ce qui a déjà été partager par des autres.
Cela permet de faire des projets rapidement et efficacement et fait une des forces majeures de python.
</p>
</article>
<article>
<h2>Vos propres modules</h2>
<p>
Vos codes commencent à être long il serait donc mieux de pouvoir
les mettre dans plusieurs fichiers et biens vous le pouvez et ceux d'une façon très simple.
</p>
<code>
def bonjour(nom):
print(f"Bonjour {nom}")
</code>
<p>
Voici un code simple que vous aimeriez utilisé dans votre programme principal,
vous avez juste à faire comme suit pour l'utiliser.
</p>
<code>
from salutation import bonjour
bonjour("Alice") # out : Bonjour Alice
</code>
<p>
Pour que tout ce passe comme prévu il faut bien que les deux fichier soit au endroit.
</p>
<figure>
<img src="images/modularite/orga.png" alt="Image de main.py et salutation.py dans un dossier nommé projet">
<figcaption>
fig.1 : main.py et salutation.py dans un dossier nommé projet
</figcaption>
</figure>
<p>
Dans le cas où il salutation serait dans un dossier nommé mesfonction,
il faudrait non plus import salutation mais mesfonction.salutation.
</p>
</article>
</div>
<div id="bottombuttons">
<a id="goprev" class="botbutton" href="yield.html">Yield</a>
<a id="gotop" class="botbutton" href="#top">Retour en haut</a>
<a id="gonext" class="botbutton" href="class.html">Class</a>
</div>
</section>
</main>
<!-- Pied de page -->
<footer>
<!-- Copyright -->
<p><img src="images/icons/bugs.png" alt="Bug"> All rights reserved - PythonMasterClass 2020 <img src="images/icons/bugs.png" alt="Bug"></p>
<!-- Réseaux -->
<address>
<p>Réseaux :</p>
<a href="https://discord.com" target="_blank"><img id=discord src="images/logos/discord.png" alt="Discord"></a>
<a href="https://fr.linkedin.com" target="_blank"><img src="images/logos/linkedin.png" alt="Linkedin"></a>
<a href="https://www.instagram.com" target="_blank"><img src="images/logos/instagram.png" alt="Instagram"></a>
<a href="https://www.youtube.com" id=youtube target="_blank"><img src="images/logos/youtube.png" alt="Youtube"></a>
<a href="https://twitter.com" target="_blank"><img src="images/logos/twitter.png" alt="Twitter"></a>
</address>
</footer>
<!-- Script de configuration du code -->
<script src="js/codemirror.js"></script>
</body>
</html>