How to create a variable List

For example, for n=5

Table[Symbol["a" <> ToString[i]], {i, 5}]

but consider that in any case it may not be optimal for what you need to do. If you want to share what you are planning to use this list for, we may help you with a better construct.


You might also try with:

Table[Unique["a"], {n}]

The advantage and disadvantage of this is that generated variables are unique - there will be no conflict with but also no reuse of existing ones.

Note: depending on what you do, you might also want to Remove such generated variables after they are no longer needed, to avoid leaking memory for unused symbols.


As stated by MarcoB, indexed variables are highly convenient and less prone to error or difficulties. They can be displayed in any manner that you desire using Format.

n = 5;

list = Array[a, n];

To display as you show

Format[a[n_]] := Symbol["a" <> ToString[n]]

list

enter image description here

To display as subscripts

Format[a[n_]] := Subscript[a, n]

list

enter image description here

Or with a specified style

Format[a[n_]] := Style[Subscript[a, n], Bold, Italic, Blue]

list

enter image description here