[Tutor] trouble with function-- trying to check differences btwn 2 strings

Rikard Bosnjakovic rikard.bosnjakovic at gmail.com
Tue Mar 6 00:41:23 CET 2007


On 3/6/07, zannah marsh <zannah.m at gmail.com> wrote:

> step through them as you would in an array or list. so i had this:
>  for i in word1
>      if word1[i] == word2[i]...

For this construction to work in Python, you use the range()-function.

for index in range(len(word1)):
    ....

Say word1 is "parrot", len(word1) == 6, range(len(word1)) = 0,1,2,3,4,5.


-- 
- Rikard.


More information about the Tutor mailing list