ReplacePart
[expr, i -> new]ReplacePart
[expr, {{i, j} -> $e_1$, {k, l} -> $e_2$}]ReplacePart[{a, b, c}, 1 -> t]
ReplacePart[{{a, b}, {c, d}}, {2, 1} -> t]
ReplacePart[{{a, b}, {c, d}}, {{2, 1} -> t, {1, 1} -> t}]
ReplacePart[{a, b, c}, {{1}, {2}} -> t]
Delayed rules are evaluated once for each replacement:
n = 1;
ReplacePart[{a, b, c, d}, {{1}, {3}} :> n++]
Non-existing parts are simply ignored:
ReplacePart[{a, b, c}, 4 -> t]
You can replace heads by replacing part 0:
ReplacePart[{a, b, c}, 0 -> Times]
(This is equivalent to Apply
.)
Negative part numbers count from the end:
ReplacePart[{a, b, c}, -1 -> t]