How to | Use Brackets and Braces Correctly
The Wolfram Language's rich syntax uses different kinds of brackets and braces; familiarity with these aspects lets you read and program efficiently in the Wolfram Language.
Parentheses ( ), braces { }, and square brackets [ ] all have different meanings in the Wolfram Language. The first two are sometimes called round brackets and curly brackets.
You use parentheses ( ) in the Wolfram Language for grouping expressions and to determine the precedence of operations:
1 + 2 / 3(1 + 2) / 3A list in the Wolfram Language is represented by braces { } and is a collection of items referred to as elements.
Create a list of the first five positive integers:
{1, 2, 3, 4, 5}Anything in the Wolfram Language can be used in lists, including numbers, variables, typeset mathematical expressions, and strings:
{1, b, 2, 3, 3x == 12, Sqrt[9 + y], "hello"}Lists can contain other lists to create nested lists:
{1, 1, {3, 4, 5}, {3, 2}}Square brackets are used in the Wolfram Language to enclose the arguments of functions.
The functions Range, Sin, and N are used here with square brackets enclosing their arguments:
Range[10]Sin[2]N[Sin[2]]The Wolfram Language uses double square brackets as the short form [[ ]] for the Part function, which is used to get parts of lists:
v = Range[10] ^ 2v[[3]]The various bracketing constructions can be used together.
Plot a function, with the range of the plot specified in a list:
Plot[Sin[x], {x, 1, 10}]The ability to use functions and lists together is seamlessly integrated in the Wolfram Language. Plot two functions together—the pair of functions is in a list:
Plot[{Sin[x], Cos[x]}, {x, 1, 10}]All bracketing characters must be balanced for the Wolfram Language to evaluate an expression. When a bracketing character is unbalanced, the the Wolfram System front end colors it purple:
(2 + πAttempting to evaluate the expression produces an error:
(2 + πFor more information on balancing brackets and braces, see How to: Balance Brackets and Braces.