Previous Up Next

6.1.6  Getting an element of a sequence or a list

The elements of a sequence have indices beginning at 0 in Xcas mode and 1 in other modes (see Section 2.5.2).

You can get the an element of index n of a sequence or list by following the sequence or list with [n] (see Section 3.2.4).

(Note that head(S) does the same thing as S[0].)

Examples

(0,3,2)[1]
     
3           
S:=2,3,4,5:; S[2]
     
4           
[A,B,C,D][2]
     
C           

For lists, the at command can also be used to get the element at a specific position.

Note.

at cannot be used for sequences, since the second argument would be merged with the sequence.

Example

[0,1,2][1]

or:

at([0,1,2],1)
     
1           

Previous Up Next