NetworkX

Previous topic

Graph

Next topic

networkx.Graph.add_nodes_from

Quick search

networkx.Graph.add_node

Graph.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 Graphs, though one should be careful that the hash doesn’t change on mutables.

Examples

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