+ 1
What python code prints out the position of a letter in a word?
it's for guess the word game
2 Respostas
+ 6
word = "metaphore"
print(word.find("a"))
print(word.index("a"))
# both methods print out 3, but index should be used only if you are sure the argument is to be found. If not found, word.find returns -1, while word.index crashes the program.
+ 1
variable_containing_word.find(variable_containing_letter)
if the word is 'game' and the letter is 'a', then the above code will return 1 (since the index starts with 0). And if it can't find the letter, it would return -1.