I am trying to figure out the syntax for evaluation an expression in Python that involves substituting a variable.
The code needs to go through a list of options, insert string input within the "{:(insert list item here)}"
Example Code (Python 3.x):
n = 11
print("my number is {:d}".format(n))
formatList = ['e', 'b', 'o', 'd', 'x', 'f', 's']
for atype in formatList:
# Failed Attempts:
# print("my number is {:eval(atype)}".format(n))
# print("my number is {:" + eval(atype) + "}".format(n))
# print(eval("my number is {:" + atype + "}").format(n))
# print(eval(' "my number is {:" + atype + "}".format(n)) '))
The output should resemble the number 11, in all the possible formats given by the list.
Thank you for everyones help!