简体   繁体   English

如何将字符串转换为对变量的调用并检索变量内容?

[英]How can I turn a string into a call to a variable and retrieve the variable contents?

I'm trying to call a different variable based on the input the function receives, but I don't know how to change the text based on the input.我试图根据函数接收的输入调用不同的变量,但我不知道如何根据输入更改文本。 How can I turn a string into a call to a variable to make my text say "you chose" and based on the decision variable, a certain choice?如何将字符串转换为对变量的调用以使我的文本说“您选择”并基于决策变量进行某个选择?

def blab(decision):
    Choice_0 = "Python Ideas"
    Choice_1 = "Website Ideas"
    Choice_2 = "Discord Ideas"
    Choice_3 = "Game Ideas"
    Choice_4 = "Robot Ideas"
    real_choice = Choice_ + decision

    deci = input(F"You chose {real_choice}")

Why not use a list ?为什么不使用list

def blab(decision):
    choices = [
        "Python Ideas"
        "Website Ideas"
        "Discord Ideas"
        "Game Ideas"
        "Robot Ideas"
    ]
    real_choice = choices[decision]

    deci = input(F"You chose {real_choice}")

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

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