NetworkX

Previous topic

DiGraph

Next topic

networkx.DiGraph.add_nodes_from

Quick search

networkx.DiGraph.add_node

DiGraph.add_node(n)

Add a single node n.

Parameters:

n : node

A node n can be any hashable Python object except None.

A hashable object is one that can be used as a key in a Python dictionary. This includes strings, numbers, tuples of strings and numbers, etc.

Notes

On many platforms hashable items also include mutables such as DiGraphs, though one should be careful that the hash doesn’t change on mutables.

Examples

>>> G=nx.DiGraph()
>>> G.add_node(1)
>>> G.add_node('Hello')
>>> K3=nx.complete_graph(3)
>>> G.add_node(K3)
>>> G.number_of_nodes()
3