feat: for
This commit is contained in:
parent
4b8f79a4c3
commit
622ea02370
21
python.md
21
python.md
@ -44,6 +44,27 @@ print(f"{a}, {b:.2f}, {s}")
|
||||
string avec `{var}` si tu veux la modifier, `{var:mod}`. `mod` est assez proche
|
||||
de ce que tu as en C.
|
||||
|
||||
## For
|
||||
1. for (int i = 0; i < 3; i++)
|
||||
```python
|
||||
for i in range(3):
|
||||
print(i) # affiche 0, 1, 2
|
||||
```
|
||||
|
||||
2. for (int i = 0; s[i] != '\0'; i++)
|
||||
```python
|
||||
s = "abc"
|
||||
for c in s:
|
||||
print(c) # affiche "a\nb\nc\n"
|
||||
```
|
||||
|
||||
2. un mixe des deux
|
||||
```python
|
||||
l = [8, 4, 7]
|
||||
for i, nb in enumerate(l):
|
||||
print(i, nb) # affiche "0 8\n1 4\n2 7"
|
||||
```
|
||||
|
||||
## Tableaux
|
||||
La syntaxe est un peu bizarre, mais elle permet d'initialiser le tableau avec
|
||||
ce que tu veux. Dans tous les exemples, `tab == tab1`.
|
||||
|
Loading…
Reference in New Issue
Block a user