Python: sleep-kommando - enkelt forklart
Søvnkommandoen i Python er ekstremt praktisk. Det får et program til å vente kort tid før du utfører ytterligere kommandoer. Her forklarer vi hvordan du kan bruke søvnkommandoen nøyaktig.
Python: Bruk søvnkommando
Du kan enkelt legge til søvnkommandoen til programkoden:
- Legg til linjen "fra import av søvn" (uten anførselstegn) til begynnelsen av koden, slik at du kan bruke søvnfunksjonen senere.
- Nå kan du legge til "sleep (1)" -kommandoen hvor som helst i koden.
- I parentes må du skrive tiden i sekunder som programmet skal vente på.
- I dette tilfellet venter programmet nøyaktig ett sekund.
Flere tips om Python i våre CHIP-guider
Tips: Du kan finne flere programmeringsopplæringer på emnesiden for Python programmeringsspråk. Der viser vi deg for eksempel hvordan du kan konvertere et heltall til en streng.