如何在字符串中包含变量?

时间:2015-05-07 16:01:32

标签: python speech

我正在做一些课程,我需要确定一个角色的名字。这就是我到目前为止所做的:

charOne=input("Please input your first character's name: ")
charTwo=input("Please input your second character's name: ")

因此用户输入名称,现在我需要让用户选择其中一个字符。

chooseCharacter=input("What character do you want to use?"

我需要将用户charOne和charTwo放入问题中。或者某种方式需要让用户选择他们想要使用的用户。

1 个答案:

答案 0 :(得分:4)

使用Python字符串格式:

charOne = input("Please input your first character's name: ")
charTwo = input("Please input your second character's name: ")

chooseCharacter = input("What character do you want to use? (%s or %s): " % (charOne, charTwo))