# Generate a list of variable names [duplicate]

How can I generate a list of variable-names like {p0, p1, p2, p3} etc...

I tried:

mylist = p # &@Range[1, 4]


But then the result is:

{p, 2 p, 3 p, 4 p}

• you could do something like ToExpression[StringJoin["p",ToString[#]]]&/@Range[4] but in general it is not recommended; the usual recommendation is to use indexed variables ie use p/@Range[4]; this seems relevant; on a different note, perhaps this is helpful, also – user42582 Jul 1 '18 at 15:30
• You could use Table[StringTemplate["p"][i], {i, 5}] (see this answer) or maybe Table["p" <> IntegerString[i, 10], {i, 1, 5}]. But, as user42582 points out, it is better to consider using indexed variables. For example: Array[p, 5] (but avoid subscripted variable names, as in Array[Subscript[a, #] &, {5}], as (IMO at least) these can cause problems). – user1066 Jul 1 '18 at 17:22