Skip to main content
`Ctrl`+`K`

# is_weighted

is_weighted(G, edge=None, weight='weight')

  Returns True if `G` has weighted edges.

  Parameters:
    G graph

      A NetworkX graph.

    edge tuple, optional

      A 2-tuple specifying the only edge in `G` that will be tested. If None, then every edge in `G` is tested.

    weight: string, optional

      The attribute name used to query for edge weights.

  Returns:
    bool

      A boolean signifying if `G`, or the specified edge, is weighted.

  Raises:
    NetworkXError

      If the specified edge does not exist.

  Examples

      >>> G = nx.path_graph(4)
      >>> nx.is_weighted(G)
      False
      >>> nx.is_weighted(G, (2, 3))
      False

      >>> G = nx.DiGraph()
      >>> G.add_edge(1, 2, weight=1)
      >>> nx.is_weighted(G)
      True