I am working on an exercise for ‘Illustrated guide to python’. and cant figure out how to add more than one argument when formatting a string. I have tried different placements and separation and can get them to work one at a time no problem.
here is the example.
car = "{:<10}".format("Car")
cost = "{:,}{:>10}".format(13499.99)
print(car+cost)
i am getting this error:
cost = “{:,}{:>10}”.format(13499.99)
IndexError: tuple index out of range
the book doesn’t really give too much explanation and the help function doesn’t mention it. Any help would be appreciated.
ok, i’ve used to wrong language when describing the problem.
so if i wanted to both format the number with commas and align could I put the format inside the same placeholder?
like :
{{:,} {:>10}}
Did you try that? It’s one (or the only) way to see if your ideas will work or not. Try them. We won’t break the computer, or the interpreter, just generate error messages that help us to learn.
Did you examine the sample I posted? Its output was,