A node or edge attribute describes its non-structural properties. For example, edge attributes may represent weight, strength, or throughput. Node attributes may represent edge, color, size, or gender. NetworkX provides mechanisms for setting, changing, and comparing attributes.
An attribute is implemented as a dictionary associated with the node or edge. The dictionary keys are attribute names. As such, they must be immutable: int, float, bool, str, and so on. There are no limitations on the values. You can create a node whose attribute is the node itself, except that this exercise is utterly pointless.
NetworkX offers three options for setting node and edge attributes.
Define attributes at the time of adding nodes or edges: ...