這裏是Hangman的源代碼。這是來自python的書籍發明遊戲。這個變量來自哪裏? Python
words = 'ant baboon badger bat bear beaver camel cat clam cobra cougar coyote crow deer dog donkey duck eagle ferret fox frog goat goose hawk lion lizard llama mole monkey moose mouse mule newt otter owl panda parrot pigeon python rabbit ram rat raven rhino salmon seal shark sheep skunk sloth snake spider stork swan tiger toad trout turkey turtle weasel whale wolf wombat zebra'.split()
def getRandomWord(wordList):
# This function returns a random string from the passed list of strings.
wordIndex = random.randint(0, len(wordList) - 1)
return wordList[wordIndex]
現在,他從哪裏得到變量wordList?這裏只有變量詞!
它是函數'getRandomWord'的一個參數。它可以被稱爲'foo',或其他任何東西 – Krease
作爲一個方面說明,這是一個從列表中獲得隨機樣本的奇怪方法。畢竟,有'random.choice()'... –
神奇的詞是:'功能參數' – bgusach