Is it posible to use docstring for plain variable? For example I have module called t
def f():
\"\"\"f\"\"\"
l = lambda x: x
\"\"\"l\"\"\"
No, you can only do this for modules, (lambda and "normal") functions and classes, as far as I know. Other objects, even mutable ones inherit the docstrings of their class and raise AttributeError if you try to change that:
>>> a = {}
>>> a.__doc__ = "hello"
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'dict' object attribute '__doc__' is read-only
(Your second example is valid Python, but the string """l""" doesn't do anything. It is generated, evaluated and discarded.)