Wolfram Language Fast Introduction for Programmers
Get Started »

Assignments

Since the Wolfram Language is dynamically typed, you don't need to specify a type when assigning variables.

Values can be assigned using =

In[1]:=
X
Out[1]=

This is immediate assignment.

An alternative is delayed assignment, where the value is recomputed every
time it is needed:

In[2]:=
X
In[3]:=
X
Out[3]=
In[4]:=
X
Out[4]=

Java does not have delayed assignments. Achieving similar functionality would require a separate method call for each update.

Python does not have delayed assignments; this would require a separate function call for each update.

Clear the assignments:

In[1]:=
X
In[1]:=
X

Using =. in the Wolfram Language is similar to setting a value to null in Java, but without the risk of NullPointerException.

The dot operator . in this context works the same as Python's del operator.

Its conventional to start variable names with lowercase letters, reserving capitals for built-in objects:

In Java, capitalized names specifically represent classes; in the Wolfram Language, capitalized names represent built-in constructs of any kind.

In Python, upper case and lower case are generally used to distinguish between classes, functions and variables.

Check Your Understanding

Which of the following will NOT evaluate to 6?

x = 4; x + 2

Incorrect. This first sets x to 4, then adds 2 to it, totaling 6.

x := 4; x + 2

Incorrect. This first gives x a delayed assignment of 4, then computes it as 4 for the "x + 2" calculation, which therefore totals 6.

x := y; y = 4; x + 2

Incorrect. This first gives x a delayed assignment of y, then sets y to 4. "x + 2" then computes x as y's current value of 4, and adds 2 to it, totaling 6.

x = 4; x =.; x + 2

Correct.

Which of these could be a user-defined variable?

x

Correct.

Clear

Incorrect. This is a built-in object. Note that built-in objects are always capitalized.

Now

Incorrect. This a built-in object. Note that built-in objects are always capitalized.

Which of the following clears any assignment for y?

y = 5

Incorrect. This creates an assignment for y.

y := x

Incorrect. This creates a delayed assignment for y.

y =.

Correct.