Institute of Computer Science
  1. Main page
  2. Teeme ise arvutimänge
ET
Log in

Teeme ise arvutimänge

  • Esileht
  • I RAAMAT
  • II RAAMAT
  • III RAAMAT
  • IV RAAMAT
  • V RAAMAT
  • VI RAAMAT

Tore on küll listis igasuguseid andmeid hoida, aga kui meil peaks andmeid vaja olema, kuidas ma leian need listist üles. Kuidas ma saan üldse kindlaks teha, et väärtus, mida ma otsin, samuti antud listis on?

Väga tihti tuleb listidega teha kahte asja:

leida, kas mingi element on antud listis või mitte leida, millisel kohal minu element listis paikneb

Võtmesõna in

Vastame kõigepealt esimesele küsimusele, kas minu element on listis?

Nagu pildilt näha võib, annab in võtmesõna kasutamine vastuseks alati tõeväärtuse, kas True või False.

 Seda Trued ja False saab ära kasutada if-lauses, kui on tõsi prindi "Leidsin!", kui ei ole tõsi prindi "Ei leidnud!".

Elemendi järjekorranumbri ehk indeksi leidmine

Otsitava elemendi järjekorranumbri ehk indeksi, ehk järjekorranumbri, saame kätte .index() käsuga:

  • 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