Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.generators.classic.complete_graph

complete_graph(n, create_using=None)[source]

Return the complete graph K_n with n nodes.

Parameters
  • n (int or iterable container of nodes) – If n is an integer, nodes are from range(n). If n is a container of nodes, those nodes appear in the graph.

  • create_using (NetworkX graph constructor, optional (default=nx.Graph)) – Graph type to create. If graph instance, then cleared before populated.

Examples

>>> G = nx.complete_graph(9)
>>> len(G)
9
>>> G.size()
36
>>> G = nx.complete_graph(range(11, 14))
>>> list(G.nodes())
[11, 12, 13]
>>> G = nx.complete_graph(4, nx.DiGraph())
>>> G.is_directed()
True