I run into the following error when attempting to format string in python,
JavaScript
x
12
12
1
TypeError: unsupported format string passed to tuple.__format__
2
3
def prop_details(address):
4
5
if address:
6
7
mv = 216164970,
8
av = 191088,
9
totalsqft = 663487
10
11
return ("${:,.0f}".format(mv), "${:,.0f}".format(av), totalsqft)
12
Advertisement
Answer
when you write:
JavaScript
1
2
1
mv = 216164970,
2
then mv
becomes a tuple
.
Try without the comma…
Also, I find the f-string syntax clearer. You may want to take advantage of it if you are using Python >=3.6:
JavaScript
1
12
12
1
def prop_details(address):
2
if address:
3
mv = 216164970
4
av = 191088
5
totalsqft = 663487
6
else:
7
mv, av, totalsqft = 0, 0, 0
8
return f'${mv:,.0f}', f'${av:,.0f}', totalsqft
9
10
>>> prop_details(1)
11
('$216,164,970', '$191,088', 663487)
12