Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

# networkx.classes.function.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

nloops – The number of selfloops.

Return type

int

Examples

>>> G = nx.Graph()  # or DiGraph, MultiGraph, MultiDiGraph, etc