0

I need to store a random initial value so it could be used later after the user enters an override. So I have to use two variables to handle the same type of data. Later it is leading to unavoidable if/elif I would like to avoid.

var01='default'
var02=None
if var01: print var01
elif var02: print var02

Question: Since the incoming initial value every time's different no defaults could be used. Ideally an initial value would simply be 'moved down data-hierarchy' and remains 'there' available. If that is not possible I would like to see how a similar situation handled properly.

3
  • Can you not use a list? Commented Apr 23, 2014 at 3:56
  • Sure... or dictionary... But I need a single variable solution. Or some other but elegant. Commented Apr 23, 2014 at 3:58
  • 2
    Is a list not a single variable? Is it not elegant? Commented Apr 23, 2014 at 4:01

1 Answer 1

3

Using list:

var_list = ['default']
print var_list[-1] # 'default'
var_list.append('new var')
print var_list[-1] # 'new var'
Sign up to request clarification or add additional context in comments.

1 Comment

So to be list! Thanks!

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.