NetworkX

Previous topic

networkx.Graph.__contains__

Next topic

networkx.Graph.has_neighbor

Quick search

networkx.Graph.has_edge

Graph.has_edge(u, v)

Return True if graph contains the edge (u,v), False otherwise.

Examples

Can be called either using two nodes u,v or edge tuple (u,v)

>>> G=nx.path_graph(4)
>>> G.has_edge(0,1)  # called using two nodes
True
>>> e=(0,1)
>>> G.has_edge(*e)  #  e is a 2-tuple (u,v)
True
>>> e=(0,1,'data')
>>> G.has_edge(*e[:2])  # e is a 3-tuple (u,v,d)
True

The following syntax are all equivalent:

>>> G.has_neighbor(0,1)
True
>>> G.has_edge(0,1)
True
>>> 1 in G[0]  # though this gives KeyError if 0 not in G
True