1

In python, is it possible to store a variable in a list? For example, if I want to have a variable depending on it's index in a list, can I do that? I can come up with an alternate solution, but I just wanted to know if something like this was possible.

An example of this scenario would be like sorting a list and having the elements represent user input.

1
  • 1
    I'm not clear what you mean by "variable dependent on its index in a list", could you give a use case or example of how you'd expect this to work? Commented Feb 22, 2017 at 0:24

1 Answer 1

1

Something like this, perhaps?

side1 = int(input("Please enter the value of side 1: "))
side2 = int(input("Please enter the value of side 2: "))
side3 = int(input("Please enter the value of side 3: "))
side_list = [side1, side2, side3]

Yes, this works just fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.