Let’s say I have a dictionary that holds numerical data, such as a measurements. And another programmer is reading my code, and can see that this is a dictionary that holds key:value pairs that look like items:measurements.
But it’s not clear what particular aspect of that item is being measured, or what unit the data is expressed in.
Technically I could make a very long variable name to make that clear. So instead of just measured_circles{} I could call my dictionary measured_diameters_of_circles_in_inches. But that’s too long a variable name. And if there’s other info I’d like to include about the data in the dictionary, such as what types of items are measured, that would make the variable name even longer.
I could instead opt to make a comment. But this too would be a very long comment. And comments are supposed to help others understand what your code is doing, not describe details of an object. A comment would also not be tied to the object in any way, such that if there’s a reference to the object somewhere else, that comment would be accessible there.
So is there a way to create something like a “docstring” for dictionaries (or at least for a few other more complex data structures), where you could include descriptive information about the data inside it, for FYI purposes?