Mathematica's sessions and notebooks (documents) are organized into "cells".

As you type something, Mathematica creates a cell; you can see the cells and how they are grouped together on the right edge of the window. The cell delimiter looks like a closing bracket. This very cell is defined as text cell, therefore can't be evaluated, i.e., it contains no definitions or expressions.

The next cell below, the one containing the expression 2+3, is an Input cell instead, and can be evaluated. By default, every new cell is an input cell. Input cells contain expressions; function definitions are also expressions.

In order to evaluate a cell you have to press Shift and Enter at the same time (Shift+Enter), or the Enter key in the numeric keypad. At that point, all the expressions in the cell are evaluated, in a top-down fashion. If one or more expressions in the cell have a return value (a result), then the evaluation of the input cell will generate one or more Output cells containing the results.

You can select (put the focus onto) a cell by clicking in the expressions within the cell, by clicking on the corresponding bracket (on the right), or by moving the up/down arrows until the cursor appears within the cell. Once a cell has the focus, it can be evaluated by pressing Shift+Enter.  

Try to give the focus to and evaluate the next cell (2+3) .

2+3

Another cell containing 5 should have appeared. 
NOTE: The very first evaluation of a Mathematica session is somewhat slow because the computational kernel has to be loaded.

The next cell contains more than one expression.
The evaluation generates three output cells. [evaluate the next cell]

k = a+5
k^2 + a^2-3a
4!/(3 a)

In the next cell, the evaluation doesn't produce any output [try]. The computation takes place regardless.

4 * Pi;

This behavior is due to the ";" at the end of the expression: it prevents the output from being displayed. ";" is also used to create a sequence of instructions.

Mathematica provides online help through the ? function.
The evaluation of "? FunctionName" returns a short description of FunctionName.

?Plot

"?" used in conjunction with the wild card * can be used to find available functions.

?*Plot

?Plot*

Note: The curly brackets "{" and "}" are used to create lists.

(* this is a comment, it's not going to be evaluated *)

a = 4;                                 (* integer *) 
b = 5.5 + Sqrt[-4.4];(* complex number *) 
c = "element";               (* string *)
d = function[ 4 ];        (* function call *)  
e = Pi;                              (* symbol *)
f = {1,2};                     (* a list *)

?d

Clear[x,y,z,a,b,c,d,e,f]

At this point, the variable x is undefined

?x

The return value of an assignment is the value of the right-hand side

x=a+3

Now x has a definition

?x

b=Pi/E

= is the assignment
:= is the delayed assignment

y=E b;
z:=E b;

{y,z}

b=E; {y,z}

E=Pi

E

= should be used to assign constants and independent variables.
:= should be used to define functions.

?y

?z

[Note for replacement rules : exactly as for assignments, replacement rules also can be immediate or delayed. See Rule (->) and RuleDelayed (:> or :->). ]

The function Clear removes any former definition of the arguments.

Clear[a,x,y,z];

x=3+a

?x

/. indicates replacement 
exp1 -> exp2 is a replacement rule; NO assignment is performed!
the right arrow is obtained with the characters "-" and ">".

x/.a->5

x

x/.{3->a}

x

No value is stored.

Careful with the syntax! The next is not a replacement, but a replacement rule.

x/.3->a

x

More replacements. The next one is a BAD IDEA!  
Why a bad idea? Because x was already the left-hand side of an assignment. (x = 3+a)
Notice the difference between

x/.{x->-10}

and

(x+10)/.{x->-10}

Also,

a

and obviously

a/.x->5

but ...

3+a/.x->10

This is how the replacement rule should be used:

x/.{3+a->10}

Let's now get back to meaningful examples.

x/.a->x

/. { rule1, rule2, .. }
is a list of replacement rules. 
Rules follow a left to right precedence. Thus, rule1 has precedence over every other rule.

x+y/.a->y

Rules are applied at the same time

x+y/.{a->y,y->4}

?Replace

x+y/.{y->4,a->y}

//. is the repeated replacement. 
The rules are applied, one at the time, until the expression does not change anymore.

?//.

?ReplaceRepeated

x+y//.{a->y,y->4}

x+y/.{a->y,y->a}

x+y//.{a->y,y->a}

x+y//.{a->y,y->2a}

??ReplaceRepeated

x+y/.{a->y,y->a}

More replacements

Successive replacement

(x+y/.{a->y})/.y->a

This can also be written as

x+y/.{a->y;y->a}

Multiple rules

{x+y}/.{{a->y},{y->a}}

Clear[a,b,x,y,z]

Examples

{3a,a^2,3^a,a^a,a!}/.a->z

{3a,a^2,3^a,a^a,a!}/.a->4

The replacement rule contains a pattern. 
[See the section on Functions to learn about patterns]

{3a,a^2,3^a,a^a,a!}/.a^_->Infinity

{3a,a^2,3^a,a^a,a!}/._^_->Infinity

{3a,a^2,3^a,a^a,a!}/.a^x_->x^a

{3a,a^(2+Pi),3^a,(a+b)^a,a!}/.a_^exp_->exp^a

Lists are the only data structure available in Mathematica. This is in line with the fact that Mathematica's roots and original phylosophy come from the funtional language Lisp. Any other data structure has to be implemented on top of lists. A matrix is a list whose entries are lists of equal length.

Curly brackets "{" "}" create lists.

{a,b,c,d,e,f}

Lists can contain elements of different types and lenghts, including empty elements and empty lists.

l = {a,b,c,4,Pi,,{},-3.5}

Convenient functions to display lists are ColumnForm[] (now superseded by Column[]) and TableForm[].

ColumnForm[l]

Column[l]

FullForm[ ] shows the internal representation.

FullForm[l]

The following example is easy to explain once you look at FullForm[ ]

l/.List->Plus

Sometimes the fancy looking TreeForm[ ] may be useful too.

TreeForm[l]

Back to lists. The i-th element of a list is extracted using double brackets:  list[[i]]
A function is invoked using single brackets instead: fun[x] 
In a list the indices range from 1 to Length[list].

(* make sure that you have evaluated the previous list definition *)

l                  (* this is the whole list *)

l[[All]]   (* same story *)

l[[1]]       (* first element *)

First[l]  (* first element again *)

l[[0]]      (* the head of the expression, in this case, List *)

Rest[l]    (* all the elements of the list except the first one *)

l[[-1]]    (* last element *)

Last[l]    (* last element *)

l[[Length[l]]]  (* again, last element *)

The functions Table[ ] and Range[ ] are also list constructors:

Table[0,{9}]

The list is not assigned, so is lost.  (but there's Out[..])

Table[Sqrt[i],{i,10}]

Table[i^i,{i,5,10}]

Table[i,{i,15,-10,-1}]

Here we build a list enumerating the 12 entries.

Table[i^2,{i,{"t","h","e","s","e",,"a","r","e",,Sqrt[12],"entries"}}]

Table[i,{i,Pi/3.,N[Sqrt[Pi]],Pi/E^3}]

The list is built by evaluating Sin[ ]; then Length[ ] returns the list's length.

Table[Sin[i^2],{i,-5,14,.2}]//Length

l0=Table[RandomInteger[10],{6}]

?RandomInteger

RandomInteger[{0,10},6]

Table[Exp[-i Pi j],{j,l0}]

Table[f[Pi],{f,{Sin,Cos,Exp,g,#^2&}}]

Range[5]

Range[Pi,3/2Pi,.1]

Array[g,6]

?Range

?Array

Multiple indices

Table[i+j,{i,3},{j,Pi,2Pi,Pi/4}]//MatrixForm

Table[i+j,{i,3},{j,Pi,2Pi,Pi/4}]//TableForm

Table[i+j,{i,Pi,2Pi,Pi/4},{j,3}]//MatrixForm

Table[{i,j,i+j},{i,Pi,2Pi,Pi/4},{j,3}]//MatrixForm

A matrix is a list whose elements are lists of equal length. 
In Mathematica matrices are defined row-wise (row by row, row-major).

M={{1,2,3,4},{5,6,7,8},{9,10,11,12}};

The proper tool to visualize matrices is MatrixForm[ ].  Sometimes TableForm[] is also useful.

M//MatrixForm

Again, Table[ ], can also be used to generate matrices.

M=Table[(Subscript[A, i,j]),{i,1,5},{j,1,6}]
M2=Table[10i+j,{i,1,5},{j,1,6}]

MatrixForm[M]

M2//MatrixForm

Accessing parts of a list. 
First element of M. Remember that M is a list of lists!

M[[1]]

Counting from the last element.

M[[-2]]

Third entry of the first element.

M[[1]][[3]]

Again, third entry of the first element, alternative syntax

M[[1,3]]

Third entry of the first element. Yet another syntax.

Part[M,1,3]

First AND third entries of the matrix.

M[[{1,3}]]//MatrixForm

Going Matlab style.
First TO third entries of the matrix.

M[[1;;3]]

3rd row

M[[3,All]]

3rd column. Be careful: same representation as a row!

M[[All,3]]

2nd to 2nd-last rows

M[[2;;-2]]

2x2 block

M[[2;;3,2;;3]]

Transpose[M]//MatrixForm

Difference between Length[ ] and Dimensions[ ].

Length[M]

Length[M//Transpose]

Dimensions[M]

Quick detour into visualization.
ListPlot[ ] is a function to visualize a list of numerical values.

ListPlot[
Table[Sin[i^2],{i,-5,4,.02}]
]

Here we use the constructors { } to build a list of pairs, i.e., a list of lists.

Table[{i,Sin[i^2]},{i,-5,4,1}]

The symbol % is used to refer to the last result. This allows to use the result from a previous computation even if that was not assigned to any variable. In this case we can access the list we just created. Similarly, %% gives the result before the last; %n and Out[n] both return the output of the n-th evaluation.

ListPlot[%]

Pay attention to the range of the x-axis. In the following case it is determined by the first entry of the couples created by Table.

ListPlot[
Table[{i,Sin[i^2]},{i,-5,4,.02}]
]

Similar plot is obtained by passing the function Sin[x^2] directly to Plot[ ]:

Plot[Sin[x^2],{x,-5,4}]

Manipulating lists: Take[], Drop[], Join[], Union[], Append[]...

l

Extracting the last 3 elements.

Take[l,-3]

Extracting the third last element. It's the Null entry.

Take[l,{-3}]

Dropping the last 3 elements.

Drop[l,-3]

Reverse[l]

Let's define another list.

Clear[l,m]

l={a,b,c,4,π,Null,{},-3.5};

m = {Pi,2,{1,Pi},c,d}

Join[ ] is used to concatenate lists.

Join[l,m]

Join[m,l]

Union[ ] instead implements the union among sets. Notice that it removes duplicates and sorts the elements.

Union[l,m]

Intersection[l,m]

Pay attention to the difference between Append[ ] (and Prepend[ ]) and Join[ ].

Append[l,m]

Prepend[l,m]

no changes to m:

m//ColumnForm

ReplacePart[ ] is used to replace one element of an expression (not necessarily a list).

ReplacePart[m,{x,y,z},2]//ColumnForm

Notice that ReplacePart performs the replacement, but does NOT assign the result!
m is unchanged.

m//ColumnForm

In order to update m, an assignment is necessary. The parenthesis are necessary here.

(m = ReplacePart[m,{x,y,z},{3,1}])//ColumnForm

m//ColumnForm

(m1=Insert[m,{1,2,3,4},-1])//ColumnForm

(m2=Insert[m1,{-1,-2,-3,-4},1])//ColumnForm

Delete[m2,{4,2}]//ColumnForm

Flatten[ ] is used to map nested expressions to a flat structure.

m2

TreeForm[m2]

Flatten[m2]

Flatten[m2]//TreeForm

Flattening only at a specific depth of the expression

Flatten[m2,1]

Flatten[m2,1]//TreeForm

m2

Flattening in a specific place of the expression

FlattenAt[m2,{4,1}]//TreeForm

FlattenAt[m2,{4,1}]

Functional Constructs: Map, Apply...

Clear[h,f,t,l]

We start with a list l

l={"a","b",3,4,{-5,x,Exp[Pi]},f[6],t[5]}

And we apply (Map[]) the function h to all the entries of the list l

Map[h,l]

TreeForm[l]

The third argument of Map specificies the level(s) at which to Map

Map[h,l,{2}]

Map[h,l,{2}]//TreeForm

Map[h,l,{1,2}]

Map[ {#,Sqrt[#]}&, l ]//MatrixForm

Careful with matrices!

Map[ v[#]&, 
{
{1,2,3},
{4,5,6}
}
]//MatrixForm

Map[ v, 
{
{1,2,3},
{4,5,6}
}
]//MatrixForm

Map[ v, 
{
{1,2,3},
{4,5,6}
},
{2}
]//MatrixForm

Map[ v, 
{
{1,2,3},
{4,5,6}
},
Infinity
]//MatrixForm

Map[ v[#]&, 
{
{1,2,3},
{4,5,6}
},
Infinity
]//TreeForm

MapAll[ v[#]&, 
{
{1,2,3},
{4,5,6}
}
]

Map works on all expressions, not just lists.

Map[v, t[23,kk,63]]

Map[v,1+Pi+c]

Map[v, t[23,kk,63], Heads->True]

A list of random integers

l=RandomInteger[{10^2,10^3},{7}]

Is there any prime number in the list?

Map[PrimeQ,l]

Is any number divisible by 17?

Map[{#,Mod[#,17]==0}&,l]

Exp[n]?

Map[{#,N[Exp[#]]}&,l]

Sin[n]/n?

Map[Sin[#]/#&,l]

Returning the n-th power of function f?

Map[
Function[{x},Sin[x]^#]&,
l
][[2]][3.]

A list of functions

lf={Sin,Cos,#^3-#&,Integrate[(1-x^2)/x^2,{x,1,#}]&}

Evaluating each function in Pi?

Map[#[Pi]&,lf]

l1={a,b,c,d,e};
l2={1,2,3,4,5};

{a,(b^2),(c^3),(d^4),(e^5)} ?

{l1,l2}//Transpose

Map[#[[1]]^#[[2]]&,Transpose[{l1,l2}]]

List of functions and list of points

lf
lx={x,y,0.,Pi}

Apply each function to the corresponding point

Transpose[{lf,lx}]

#[[1]][#[[2]]]&

Map[#[[1]][#[[2]]]&,Transpose[{lf,lx}]]

MapIndexed[] provides a second argument (the position) to the function.This argument can be accessed by #2.

Map[v,{a,b,c,d,e}]
MapIndexed[v,{a,b,c,d,e}]

MapIndexed[ #1^#2[[1]]&, {a,b,c,d,e}]

When mapping to a level > 1, the position is a list of indexes

TreeForm[{{a,b},{c,d},e}]

MapIndexed[ v, {{a,b},{c,d},e},{2}]

MapThread[] lets one map a function over two or more lists (they have to have the same structure)

l1={1,2,3,4};
l2={a,b,c,d};
l3=Table[Random[],{4}];

MapThread[ t, {l1,l2,l3}]

Apply[] passes all the arguments to a function

Apply[ff,{1,2,3,4,5}]

Apply[Times,{a,2,b,4}]

Apply[Plus,{{1,a},{2,b},{4,d}}]

Apply[Join,{{1},{2,3},{4,5}}]

Syntax

Map[g,{arg0,arg1,arg2}]
g/@{arg0,arg1,arg2}

Apply[g,{arg0,arg1,arg2}]
g@@{arg0,arg1,arg2}

Map[t,l1]

t@l1

t/@l1

t@@l1

More:  Inner[], Outer[], Thread[]...

Inner[Times,{1,2,3,4},{a,b,c,d},Plus]  (* inner product *)

Inner[Plus,{1,2,3,4},{a,b,c,d},Times]

Inner[{#1,#2}& ,{1,2,3,4},{a,b,c,d},Plus]

Select[], Cases[], Position[], Count[]...

?Select

Select[
Table[Random[],{10}],
#>.5&]

Cases[{a, a^b, 3^Pi, Pi^3}, _^_]

Position[{a, a^b, 3^Pi, Pi^3}, _^_]