number_of_selfloops

number_of_selfloops(G)[source]

Returns the number of selfloop edges.

A selfloop edge has the same node at both ends.

Returns
nloopsint

The number of selfloops.

Examples

>>> G = nx.Graph()  # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge(1, 1)
>>> G.add_edge(1, 2)
>>> nx.number_of_selfloops(G)
1