Dec-12-2021, 07:50 PM
I write the following code and get the following error.
use the empty string as the self argument. Could someone explain it to me?
import random word_list = ['a', 'ranom', 'list', 'of', 'words'] class Word: def get_word(self): words = random.choice(word_list) return words w = Word.get_word() print(w)
Error:Traceback (most recent call last):
File "c:\Users\mcmxl\mystuff\hangman\test_hangman.py", line 13, in <module>
w = Word.get_word()
TypeError: get_word() missing 1 required positional argument: 'self'
If I change line 13 to w = Word.get_word('')
everything works fine. I know there is a way to make it so I don't have touse the empty string as the self argument. Could someone explain it to me?