Variables & Functions
Variables start with letters and can also contain numbers:
(It’s best to start with lowercase letters, reserving capitals for built-in objects.)
Out[1]= | |
A space between two variables or numbers indicates multiplication:
(In other words, “a b” is a times b, whereas “ab” is the variable ab.)
Out[2]= | |
Use /. and
to make substitutions in an expression:
(The “rule”
can be typed as ->.)
Out[3]= | |
Assign values using the = symbol:
Use your variable in expressions and commands:
Clear the assignment, and x remains unevaluated:
Define your own functions with the construction f[x_]:=
x_ means that x is a pattern that can have any value substituted for it.
:= means that any argument passed to f is substituted into the right-hand side upon evaluation:
Out[2]= | |
QUICK REFERENCE: Defining Variables and Functions »