Does a Python equivalent to the Ruby ||= operator (\"set the variable if the variable is not set\") exist?
||=
Example in Ruby :
variable_n
No, not knowing which variables are defined is a bug, not a feature in Python.
Use dicts instead:
d = {} d.setdefault('key', 1) d['key'] == 1 d['key'] = 2 d.setdefault('key', 1) d['key'] == 2