Network.add_node

Network.add_node(key=None, attr_dict=None, **kwattr)[source]

Add a node and specify its attributes (optional).

Parameters:
keyhashable, optional

An identifier for the node. Defaults to None, in which case an identifier of type int is automatically generated.

attr_dictdict[str, Any], optional

A dictionary of vertex attributes.

**kwattrdict[str, Any], optional

A dictionary of additional attributes compiled of remaining named arguments.

Returns:
hashable

The identifier of the node.

Notes

If no key is provided for the node, one is generated automatically. An automatically generated key increments the highest integer key in use by 1.

Examples

>>> graph = Graph()
>>> node = graph.add_node()
>>> node
0