1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How do I get user input to refer to a variable in Python?

Discussão em 'Python' iniciado por Stack, Setembro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to get user input to refer to some list in my code. I think it's called namespace? So, what would I have to do to this code for me to print whatever the user inputs, supposing they input 'list1' or 'list2'?

    list1 = ['cat', 'dog', 'juice']
    list2 = ['skunk', 'bats', 'pogo stick']

    x = raw_input('which list would you like me to print?')


    I plan to have many such lists, so a series of if...then statements seems unruly.

    Continue reading...

Compartilhe esta Página