Institute of Computer Science
  1. Main page
  2. Python koolis
ET
Log in

Python koolis

  • Sissejuhatus
  • Teemad

1. Paigaldamine
2. Kommentaarid
3. Muutujad
4. Andmetüübid
5. Sõned
6. Operaatorid
7. Sisend ja väljund
8. Tingimus
9. Tsükkel
10. Algoritm ja plokkskeem
11. Järjend
12. Sõnastik
13. Funktsioon
14. Failioperatsioonid
15. Moodulid
16. Objektid

  • PyGame
  • ÜLESANDED

6. Operaatorid

Andmete töötlemisel kasutatakse erinevaid aritmeetilisi operaatoreid:

  • + liitmine
  • - lahutamine
  • * korrutamine
  • / jagamine
  • // täisarvuline jagamine (alles jääb tulemuse täisarvuline osa, näiteks 5 // 2 = 2)
  • % jäägi leidmine (5 % 2 = 1)
  • ** astendamine

Sarnaselt matemaatikas õpitule arvestatakse meile matemaatikast tuntud tehete järjekorda (tehte "3+4*5" puhul enne korrutatakse ja alles siis liidetakse jne). Tehete järjekorra muutmiseks kasutame sulgusid (näiteks "(3+4)*5").

Valikut toodud operaatoritest saab kasutada ka sõnede puhul:

  • + sõnede ühendamine
print("Tere, " + "maailm") # Väljund: Tere, maailm
  • sõnede kordamine
print("tere" * 3) # Väljund: tereteretere

Lisaks aritmeetilistele operaatoritele kasutatakse võrdlusoperaatoreid (<, > jne) ja loogilkaoperaatoreid (and, or, not) avaldise tõeväärtuse leidmiseks, neist tuleb juttu tingimuslause teema juures.

Arvude ümardamiseks võime kasutada funktsioonid round, mille järel olevates sulgudes esimesel kohal on ümardatav arv, teisel aga arv, mis näitab, mitu kohta peale koma ümardamine toimub):

round(123.456, 2)
123.46
round(123.456, -1)
120

Creative Commons litsentsiga Autorile viitamine + Mitteäriline eesmärk 3.0 Eesti (CC BY-NC 3.0 EE) - https://creativecommons.org/licenses/by-nc/3.0/ee/

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment