Graph.has_edge#
- Graph.has_edge(u, v)[源代码]#
如果边(u,v)在图中,则返回true。
这和
v in G[u]
没有键错误异常。- 参数
- u, v节点
例如,节点可以是字符串或数字。节点必须是可散列(而不是无)的Python对象。
- 返回
- edge_ind布尔尔
如果边在图形中,则为True,否则为False。
实例
>>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.has_edge(0, 1) # using two nodes True >>> e = (0, 1) >>> G.has_edge(*e) # e is a 2-tuple (u, v) True >>> e = (0, 1, {"weight": 7}) >>> G.has_edge(*e[:2]) # e is a 3-tuple (u, v, data_dictionary) True
以下语法是等效的:
>>> G.has_edge(0, 1) True >>> 1 in G[0] # though this gives KeyError if 0 not in G True