Python-kielisen ohjelmoinnin perusteet/Ensimmäinen python-ohjelma
From Wikiversity
|
Please do not edit this page on betawikiversity. |
|
| Current work has been transferred from betawikiversity to this page on the new fi.Wikiversity.
In the respect about the GFDL and the CC-by-sa licenses, all the text, history and account are be preserved in the transfert. In case of problem, leave a message here to resolve it quickly |
|
| Now, you can continue to work on this page, go to the new wiki with the links above. Maybe you need to create the same account on this new project. So just transform your betawikiversity account to the Unified Login : just click here. |
Ohjelman kirjoitus
Python Shellin mukana tulee python-kielen syntaksiväritystä tukeva editori, joka käynnistyy filevalikosta "New Window"-valinnalla.
- Esimerkkiohjelma
#!/usr/bin/env python import math print math.sqrt(5)
- Esimerkkiohjelman luonti ja suoritus Windows-ympäristössä
- Avaa Pythonin mukana tullut IDLE (Python GUI)
- Avaa uusi editointi-ikkuna filevalikosta "New Window"-valinnalla sekä kopioi ja liitä yllä oleva teksti editoriin.
- Tallenna nimellä ekatesti.py. Muista tiedostopääte .py, koska IDLE ei lisää tiedostomuotoa automaattisesti.
- Käynnistä ohjelman suoritus editointi-ikkunan Run-valikon "Run Module"-toiminnolla
- Ohjelma tulostaa Shell-ikkunaan: 2.2360679775
[edit] Aiheesta muualla
- Creating_Python_programs
- Notepad++ editori tukee myös python-kielen syntaksiväritystä.