Python: commande sleep - expliqué simplement
La commande sleep en Python est extrêmement pratique. Il oblige un programme à attendre un court instant avant d'exécuter d'autres commandes. Ici, nous expliquons comment utiliser la commande sleep exactement.
Python: utiliser la commande sleep
Vous pouvez facilement ajouter la commande sleep à votre code de programme:
- Ajoutez la ligne "from time import sleep" (sans guillemets) au début de votre code afin de pouvoir utiliser la fonction sleep ultérieurement.
- Vous pouvez maintenant ajouter la commande "sleep (1)" n'importe où dans le code.
- Entre parenthèses, vous devez écrire le temps en secondes pendant lequel le programme doit attendre.
- Dans ce cas, le programme attend exactement une seconde.
Plus de conseils sur Python dans nos guides CHIP
Astuce: vous pouvez trouver plus de didacticiels de programmation sur notre page de rubrique sur le langage de programmation Python. Là, nous vous montrerons, par exemple, comment convertir un entier en chaîne.