python
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| python [2024/04/27 18:33] – root | python [2024/04/27 18:44] (Version actuelle) – root | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== PROGRAMMATION PYTHON ====== | + | {{:recap-python.pdf}} |
| - | + | ||
| - | ===== Types de variables ===== | + | |
| - | + | ||
| - | a = “Bonjour“ # chaine de caractères | + | |
| - | b = 5 # nombre entier : int\\ | + | |
| - | c = 1.5 # nombre à virgules : float\\ | + | |
| - | d = True # True ou False : bool\\ | + | |
| - | + | ||
| - | ==== Print et Input ==== | + | |
| - | + | ||
| - | nom = input(“Quel est votre nom? “) | + | |
| - | print(“Vous vous appelez “ + nom) # concaténation de chaine | + | |
| - | print(f“Vous vous appelez {nom}“) # chaine formatée | + | |
| - | print(“Vous vous appelez %s“ % nom) # chaine formatée (ancien format) | + | |
| - | Commentaires | + | |
| - | # Commentaire sur une ligne | + | |
| - | “““ Commentaire | + | |
| - | sur | + | |
| - | plusieurs lignes“““ | + | |
| - | Conversions | + | |
| - | age = 30 | + | |
| - | print(“Votre age est: “ + str(age)) # conversion de int vers str, et concaténation | + | |
| - | age_str = “30“ | + | |
| - | age_int = int(age_str) # conversion de str vers int. | + | |
| - | # Utiliser un bloc try/except en cas d’erreur | + | |
| - | Boucle While | + | |
| - | Boucle tant que la condition est vraie | + | |
| - | nom = ““ | + | |
| - | while nom == ““: | + | |
| - | nom = input(“Quel est votre nom? “) | + | |
| - | FORMATION PYTHON | + | |
| - | Boucle For | + | |
| - | Boucle un nombre de fois | + | |
| - | for i in range(0, 4): # de 0 (inclus) à 4 (exclu) : 0, 1, 2, 3 | + | |
| - | print(i) | + | |
| - | Fonctions | + | |
| - | # Définition (taille est un paramètre optionnel) | + | |
| - | def afficher_informations_personne(nom, | + | |
| - | print(" | + | |
| - | # Appel | + | |
| - | afficher_informations_personne(“Jean“, | + | |
| - | # Return : Retourner une valeur ou sortir de la fonction directement | + | |
| - | Conditions | + | |
| - | == # égal | + | |
| - | <= # inférieur ou égal | + | |
| - | < # inférieur | + | |
| - | >= # supérieur ou égal | + | |
| - | > # supérieur | + | |
| - | if age == 17: | + | |
| - | print(" | + | |
| - | elif 12 <= age < 18: | + | |
| - | print(" | + | |
| - | elif age == 1 or age == 2: | + | |
| - | print(" | + | |
| - | elif age >= 18: | + | |
| - | print(" | + | |
| - | else: | + | |
| - | print(" | + | |
| - | Exception | + | |
| - | try: | + | |
| - | age_int = int(age_str) | + | |
| - | except: | + | |
| - | print(" | + | |
python.1714242794.txt.gz · Dernière modification : de root
