This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)


Updated In 6 Graphic
ReplacePart[expr, i->new]
yields an expression in which the i^(th) part of expr is replaced by new.
ReplacePart[expr, {i1->new1, i2->new2, ...}]
replaces parts at positions in by newn.
ReplacePart[expr, {i, j, ...}->new]
replaces the part at position {i, j, ...}.
ReplacePart[expr, {{i1, j1, ...}->new1, ...}]
replaces parts at positions {in, jn, ...} by newn.
ReplacePart[expr, {{i1, j1, ...}, ...}->new]
replaces all parts at positions {in, jn, ...} by new.
  • Explicit negative part numbers count from the end.  »
  • Part position specifications can be patterns.
  • Each pattern is effectively tested against each list of part numbers for parts in expr.
  • Patterns p (such as x_) that are not explicitly lists are treated as {p}.
  • Patterns can include constructs such as __, representing position specifications of variable lengths.
  • ReplacePart[expr, i:>new] can be used to replace a part without first evaluating it. With a rule such as patt:>new, new is evaluated separately for each position that matches patt.
  • With the default option setting Heads->Automatic, a head is replaced only when the corresponding position specification is explicitly 0.
  • With Heads->True a head is replaced whenever the corresponding position specification matches 0.
New in 2 | Last modified in 6