Fiche de Revision Python - Debutant
1. Variables et types de donnees
Une variable sert a stocker une valeur.
Exemples :
nom = "Alice" # Chaine de caracteres (str)
age = 20 # Entier (int)
taille = 1.75 # Flottant (float)
est_etudiant = True # Booleen (bool)
2. Fonctions print() et input()
print() sert a afficher des choses a l'ecran.
Exemple :
print("Bonjour")
input() sert a demander a l'utilisateur de taper une valeur.
Exemple :
nom = input("Comment tu t'appelles ? ")
3. Operations arithmetiques
+ addition
- soustraction
* multiplication
/ division
// division entiere
% modulo (reste)
// puissance
Exemple :
Fiche de Revision Python - Debutant
a = 5 + 3 # vaut 8
4. Conditions (if, elif, else)
Exemple :
age = 18
if age >= 18:
print("Majeur")
else:
print("Mineur")
5. Boucles (for, while)
for i in range(5):
print(i) # Affiche 0 a 4
i=0
while i < 5:
print(i)
i += 1
6. Fonctions (def)
def bonjour(nom):
print("Bonjour", nom)
bonjour("Alice")
7. Listes (tableaux)
Fiche de Revision Python - Debutant
nombres = [1, 2, 3]
print(nombres[0]) # Affiche 1
[Link](4) # Ajoute 4 a la liste
8. Erreurs courantes
- Oublier les deux-points ':' apres if, for, def...
- Mauvaise indentation (toujours 4 espaces)
- Types incompatibles : "3" + 2 (ne marche pas)