Skip to content

Commit a7101ac

Browse files
committed
29072025
1 parent 636071a commit a7101ac

14 files changed

Lines changed: 719 additions & 328 deletions
Binary file not shown.
Binary file not shown.

Try&Except.py renamed to Exceptions.py

Lines changed: 502 additions & 301 deletions
Large diffs are not rendered by default.

‎Files.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329

330330

331331
### STRERROR()
332-
# comes from the os module
332+
# comes from the OS module
333333
# 1 * argument = error number
334334
# returns a string describing the meaning of the error
335335

‎Functions-LAMBDA.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ def f(a, b):
7171
# La fonction f prend deux arguments : a (une fonction) et b (une valeur)
7272

7373
print(f(lambda x: x and True, 1 > 0))
74-
# 1er argument a est une lambda : lambda x: x and True == True + True
75-
# 2ème argument b est 1 > 0, ce qui retourne True
74+
# ==> évalue x and True pour x = 1>0, = True, True and True = True
7675
# True
7776

7877

‎Functions.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def fun(data, *num ):
313313
# Earth
314314

315315

316-
# on peut avoir une fonction dans une fonction etc
316+
# on peut avoir une fonction dans une fonction
317317
x = 5
318318
def outer_func():
319319
y = 3
@@ -333,6 +333,15 @@ def embed(y):
333333
print(dq('Jane Doe'))
334334
# "Jane Doe"
335335

336+
# ==>
337+
# quote(quo) : fonction qui crée une autre fonction
338+
# embed(str), qui utilise la valeur quo capturée, ici ", est une fonction anonyme
339+
# dblq = quote("") ==> quote() retourne la fonction embed(str) où quo est maintenant "
340+
# dblq devient cette fonction embed(str)
341+
# dblq('Jane Doe') ==> embed('Jane Doe'), return " + Jane Doe + "
342+
343+
344+
336345

337346

338347
## create Documentation about a function we create with a DOCSTRING

‎Module-MATH.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
########## MATH MODULE ##########
22

3+
https://docs.python.org/fr/3.13/library/math.html
34

45
# MATH module comes with the standard Python release, and contains some useful constants and functions for carrying out mathematical operations
56
# Note: all trigonometrical functions take their arguments expressed in radians
@@ -17,7 +18,7 @@
1718
### Racine carrée
1819

1920
## math.sqrt(x)
20-
# racine carrée de x
21+
# racine carrée de x, en float
2122

2223
print(math.sqrt(16))
2324
# 4.0
@@ -317,4 +318,10 @@
317318
print(math.hypot(1, 1))
318319
# 1.4142135623730951 (√2)
319320
print(math.hypot(5, 12))
320-
# 13.0 (triangle 5-12-13)
321+
# 13.0 (triangle 5-12-13)
322+
323+
# si on ne met qu'un seul argument, int ou float, le return sera la meme valeur en float
324+
print(math.hypot(4.0))
325+
# 4.0
326+
print(math.hypot(4))
327+
# 4.0

‎Module-PLATFORM.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070
## platform.python_implementation()
7171
# returns a string denoting the Python implementation
72+
# return values are CPython , IronPython , Jython , PyPy
7273

7374
from platform import python_implementation
7475
print(python_implementation())

‎Module-RANDOM.py‎

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,17 @@
4747
0.5112747213686085
4848
# same values each time
4949

50+
# maximum 2 arguments: le premier étant la graine, le deuxième optionnel version
51+
seed(1, 2, 3)
52+
for i in range(5):
53+
print(random())
54+
# TypeError: Random.seed() takes from 1 to 3 positional arguments but 4 were given
5055

5156

52-
### random()
57+
58+
### .random()
5359
# produces a float number x, which falls within the range 0.0 ≤ x < 1.0
60+
# ne prend PAS d'argument
5461

5562
import random
5663
print(random.random())
@@ -65,9 +72,12 @@
6572
0.9930295466333776
6673
0.023790533052207796
6774

75+
print(random.random(4))
76+
# TypeError: Random.random() takes no arguments (1 given)
77+
6878

6979

70-
### random.randrange(start, stop ,step)
80+
### randrange(start, stop ,step)
7181
# produces an integer number x, which is taken from the range start ≤ x < stop with step
7282
# start argument defaults to 0
7383
# step argument defaults to 1
@@ -88,7 +98,7 @@
8898

8999

90100

91-
### random.randint(start, stop)
101+
### .randint(start, stop)
92102
# stop inclus
93103

94104
from random import randrange, randint
@@ -110,12 +120,13 @@
110120

111121

112122

113-
### random.choice(liste, tuple, string)
123+
### .choice(liste, tuple, string)
114124

115-
from random import choice
125+
from random import choice,choices
116126
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
117127
tup = 20,23,24
118128
var = "palestine"
129+
119130
print(choice(lst)) # 1 element de la list
120131
# 9
121132
print(choice(tup)) # 1 elem du tuple
@@ -125,9 +136,28 @@
125136

126137

127138

128-
### random.sample(lst/tupple/string,int)
139+
### .choices((liste, tuple, string), weights, k)
140+
# returns a list
141+
# weights == poids pour chaque elem de la list
142+
# k == nombre de réptition
143+
print(choices(lst, weights = [10,1,1,1,1,1,1,1,1,1], k = 14))
144+
# [5, 1, 4, 9, 1, 10, 4, 5, 6, 10, 3, 1, 1, 9]
145+
print(choices(tup, weights = [10,1,1], k = 5))
146+
# [20, 23, 20, 20, 20]
147+
148+
149+
150+
### .sample(lst/tupple/string,int)
129151
from random import sample
130152
print(sample(lst, 5)) # 5 elements de la liste dans un sens au hasard
131153
[10, 9, 8, 1, 4]
132154
print(sample(lst, 10)) # 10 elements de la liste dans un sens au hasard
133-
[4, 10, 5, 2, 7, 3, 9, 6, 1, 8]
155+
[4, 10, 5, 2, 7, 3, 9, 6, 1, 8]
156+
157+
# avec k, positionnal argument
158+
print(random.sample([ "spam" , "ham" , "eggs" ], k = 2 ))
159+
# ['eggs', 'spam']
160+
print(random.sample(k = 2, [ "spam" , "ham" , "eggs" ] ))
161+
# SyntaxError: positional argument follows keyword argument
162+
print(random.sample([ "spam" , "ham" , "eggs" ], 2 ))
163+
# ['ham', 'eggs']

0 commit comments

Comments
 (0)