[Tutor] I don't understand this code
Michael M Mason
michael at shamirlens.co.uk
Wed Jul 14 12:59:44 CEST 2010
> The thing is, the "passed list of strings" is called "words",
> not "wordList", so I see it shouldn't work.
>
> On the other hand, the variable "wordList" is defined nowhere!
"wordList" is just a name that the function (getRandomWord) uses to
refer to
whatever values get passed to it. Remember that you don't have to put
your
list of words into a variable before you call the function. You could
just
do this:-
getRandomWord('ant baboon badger bat bear')
...and it will work. Or consider having two or three variables:-
words = 'ant baboon badger bat bear'
mylist = 'left right backward forward up down'
morestuff = 'run walk stand sit'
Naturally you can feed any of these into the function:-
getRandomWord(words)
getRandomWord(mylist)
getRandomWord(morestuff)
You can think of "getRandomWord(wordList)" as a convenient
shorthand for:-
wordList = words
getRandomWord(wordList)
Hope this helps
--
Michael
More information about the Tutor
mailing list