Put Python special symbol number right in front of it

Asked 2 years ago, Updated 2 years ago, 16 views

//Cash=6600.0
AR=6200.0
tne=25000.0
TotalAssets=Cash+AR+tne
np=5000.0
ap=25000.0
TL=np+ap
Capitalstock=7000.0
re=800.0
totalEquity=Capitalstock+re
total=TL+totalEquity

print("{0:<21s}""${1:>20,.0f}""{2:<2}""{3:<21s}""${4:>21,.0f}".format("Total",total,"","Total",total))

where the output value is

It comes out like this.

I'd like to put a total of 21 spaces and a total of 37,800 spaces and put a dollar sign right in front of the number for $37,800, what should I do?

python

2022-09-22 19:17

1 Answers

In the front of the output statement "${1:>20,.0f}"

":>" is a grammar for right alignment.

I think the dollar and the number are 20 spaces apart.

Exclude the grammar that aligns in that part

All you need to do is write "${1:0.1f}".


2022-09-22 19:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.