Python: nukkumiskomento - yksinkertaisesti selitetty
Pythonin unikomento on erittäin käytännöllinen. Se saa ohjelman odottamaan vähän aikaa ennen kuin suoritat uusia komentoja. Tässä selitetään kuinka nukkumiskomentoa käytetään tarkalleen.
Python: Käytä nukkumiskomentoa
Voit helposti lisätä lepokomennon ohjelmakoodiin:
- Lisää rivi "ajasta tuota nukkumista" (ilman lainausmerkkejä) koodin alkuun, jotta voit käyttää nukkumistoimintoa myöhemmin.
- Nyt voit lisätä "uni (1)" -komennon mihin tahansa koodin osaan.
- Suluissa on kirjoitettava sekunteina aika, jonka ohjelman odotetaan.
- Tässä tapauksessa ohjelma odottaa tarkalleen sekunnin.
Lisää vinkkejä Pythonista CHIP-oppaissamme
Vinkki: Löydät lisää ohjelmointiohjeita Python-ohjelmointikielen aiheisivulta. Siellä me esimerkiksi osoitamme, kuinka voit muuntaa kokonaisluvun merkkijonoksi.