Skip to content
Snippets Groups Projects
Commit 0152a1e0 authored by Joel Cavat's avatar Joel Cavat
Browse files

Add python example

parent e2122d7c
Branches
No related tags found
No related merge requests found
......@@ -22,6 +22,28 @@
- [sbd] chapitre 2 - modélisation EA
- [sbd] exercices
Comparaison en Python d'une manipulation d'une collection avec un style impératif et déclaratif (compréhension de listes)
```python
from dataclasses import dataclass
@dataclass
class Student:
lastname: str
firstname: str
age: int
students = [ Student("Cavat", "Joel", 40),
Student("Albuquerque", "Paul", 17), Student("Orestis", "Malaspinas", 32) ]
# impératif
res = []
for s in students:
if s.age >= 18:
res.append( s.lastname )
# déclaratif
res = [ s.lastname for s in students if s.age >= 18 ]
```
### Semaine 2
- programme planifié
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment