Either you use hasattr
:
if not hasattr(A, 'var'):
A.var = 'foo'
or, as some would prefer according to the "Easier to ask for forgiveness than permission" principle:
try:
A.var
except NameError:
A.var = 'foo'
Finally, you can simply define the default value in the class body:
class A(object):
var = None
...
if A.var is None:
a.var = 'foo'
(Note that neither approach is thread-safe)