以下程序在字符串中使用{0},我不確定它是如何工作的,它出現在關於Python迭代的在線教程中,我似乎無法在任何地方找到解釋它的地方。這個Python字符串中的{0}是什麼意思?
import random
number = random.randint(1, 1000)
guesses = 0
print("I'm thinking of a number between 1 and 1000.")
while True:
guess = int(input("\nWhat do you think it is? "))
guesses += 1
if guess > number:
print("{0} is too high.".format(guess))
elif guess < number:
print("{0} is too low.".format(guess))
else:
break
print("\nCongratulations, you got it in {0} guesses!\n".format(guesses))
謝謝!
太好了,謝謝!這就說得通了。 – Elizabeth