Python: Assign Value if None Exists
I am a RoR programmer new to Python. I am trying to find the syntax that will allow me to set a variable to a specific value only if it wasn't previously assigned. Basically I want: # only if var1 has not been previously assigned var1 = 4 This is a very different style of programming, but I always try to rewrite things that looked like bar = None if foo(): bar = "Baz" if bar is None: bar = "Quux" into just: if foo(): bar = "Baz" else: bar = "Quux" That is to say, I try hard to avoid a situation where some code paths define variables but others don't. In my code, there is never a path which