Mathematica 9 is now available
 Documentation / Mathematica / Built-in Functions / Programming / Expression Structure  /
Part

  • expr [[ i ]] or Part[ expr , i ] gives the i part of expr.
  • expr [[- i ]] counts from the end.
  • expr [[0]] gives the head of expr.
  • expr [[ i , j , ... ]] or Part[ expr , i , j , ... ] is equivalent to expr [[ i ]] [[ j ]] ... .
  • expr [[ , , ... ]] gives a list of the parts , , ... of expr.
  • You can make an assignment like t [[ i ]] = value to modify part of an expression.
  • When expr is a list, expr [[ , , ... ]] gives a list of parts. In general, the head of expr is applied to the list of parts.
  • You can get a nested listing of parts from expr [[ , , ... ]]. Each part has one index from each list.
  • Notice that lists are used differently in Part than in functions like Extract, MapAt and Position.
  • expr [[ Range[ i , j ] ]] can be used to extract sequences of parts.
  • In StandardForm and InputForm, expr [[ spec ]] can be input as exprspec.
  • and can be entered as [[ and ]] or \[LeftDoubleBracket] and \[RightDoubleBracket].
  • See the Mathematica book: Section 1.2.4, Section 1.2.4, Section 1.4.6, Section 1.8.4, Section 1.8.4Section 2.1.4.
  • See also: First, Head, Last, Extract, Position, ReplacePart, MapAt, Take.
  • Related package: LinearAlgebra`MatrixManipulation`.

    Further Examples

    This extracts the third element from the list.

    In[1]:=

    Out[1]=

    This extracts a list of elements.

    In[2]:=

    Out[2]=

    The second input resets the third element of the list.

    In[3]:=

    Out[3]=

    In[4]:=

    Out[4]=

    In[5]:=

    Out[5]=

    In[6]:=

    This picks out parts 2 and 4 of the sum, leaving their sum.

    In[7]:=

    Out[7]=



    Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
    THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
    SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.