Did I find the right examples for you? yes no

All Samples(12)  |  Call(12)  |  Derive(0)  |  Import(0)
Pattern matching.

Wild symbols match all.

Return None when expression (self) does not match
with pattern. Otherwise return a dictionary such that

  pattern.subs(self.match(pattern)) == self

Example:(more...)

src/s/y/sympy-HEAD/sympy/core/tests/test_match.py   sympy(Download)
    r = Wild('r')
 
    assert p.match(q + r) in [ {q: p, r: 0}, {q: 0, r: p} ]
    assert p.match(q*r) in [ {q: p, r: 1}, {q: 1, r: p} ]
 
    p = Wild('p')
    q = Wild('q', exclude=[p])
    r = Wild('r')
 
    assert p.match(q + r) == {q: 0, r: p}
 
    assert p.match(q + r) == {q: 0, r: p}
    assert p.match(q*r) == {q: 1, r: p}
 
    p = Wild('p')
    q = Wild('q', exclude=[p])
    r = Wild('r', exclude=[p])
 
    assert p.match(q + r) is None

src/s/y/sympy-polys-HEAD/sympy/core/tests/test_match.py   sympy-polys(Download)
    r = Wild('r')
 
    assert p.match(q+r)  in  [ {q: p, r: 0} , {q: 0, r: p} ]
    assert p.match(q*r)  in  [ {q: p, r: 1} , {q: 1, r: p} ]
 
    r = Wild('r')
 
    assert p.match(q+r) == {q: 0, r: p}
    assert p.match(q*r) == {q: 1, r: p}
 
    p = Wild('p')
    q = Wild('q', exclude=[p])
    r = Wild('r', exclude=[p])
 
    assert p.match(q+r) == None