Does a Python equivalent to the Ruby ||= operator (\"set the variable if the variable is not set\") exist?
Example in Ruby :
variable_n
I think what you are looking for, if you are looking for something in a dictionary, is the setdefault method:
(Pdb) we=dict()
(Pdb) we.setdefault('e',14)
14
(Pdb) we['e']
14
(Pdb) we['r']="p"
(Pdb) we.setdefault('r','jeff')
'p'
(Pdb) we['r']
'p'
(Pdb) we[e]
*** NameError: name 'e' is not defined
(Pdb) we['e']
14
(Pdb) we['q2']
*** KeyError: 'q2' (Pdb)
The important thing to note in my example is that the setdefault method changes the dictionary if and only if the key that the setdefault method refers to is not present.