小编Eli*_*eth的帖子

{0}在这个Python字符串中的含义是什么?

以下程序在字符串中使用{0},我不确定它是如何工作的,它出现在一个关于Python迭代的在线教程中,我似乎找不到任何解释它的地方.

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))
Run Code Online (Sandbox Code Playgroud)

谢谢!

python python-3.x

26
推荐指数
4
解决办法
5万
查看次数

标签 统计

python ×1

python-3.x ×1