简体   繁体   English

Python避免覆盖变量

[英]Python Avoid overwriting variables

So I am making a text game in python 2.7.9 and when you adopt a dog I would normally do something like this: 所以我正在用python 2.7.9编写文本游戏,当您领养狗时,我通常会这样做:

Jim = Dog("Jim")

But I created a while true loop which has an option that you can choose which adopts a dog. 但是我创建了一个while true循环,它具有一个选项,您可以选择采用哪种狗。 I can create it using their input but I can't just make the same variable = Dog("Name") since it would override their other dog. 我可以使用他们的输入来创建它,但我不能仅仅使用相同的变量= Dog("Name")因为它将覆盖他们的另一只狗。 How would I do this? 我该怎么做?

You could try to make a list instead: 您可以尝试列出一个列表:

Jim = []
while True:
    #*insert code here*
    Jim.append(Dog("name"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM