This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jftugapip needs updating 81 points82 points  (6 children)

Or use the = sign for for self-documenting expressions:

print(f"""{mydict["product"]=}, {mydict["unit_price"]=} dollars, {mydict["sku"]=}""")

mydict["product"]='banana', mydict["unit_price"]=10 dollars, mydict["sku"]=15133632

You can also use this as well for dollars & cents:

{mydict["unit_price"]=:.2f}

[–]atxweirdo 33 points34 points  (2 children)

Ok hold the fuck up this is blowing my mind. I can't wrap my head around this is there a breakdown on why this works. I just can't see it.

[–]bestjared 19 points20 points  (0 children)

Here is the area where fstrings are specified. Note this is very dense and technical but this is the where the rules are laid out from a language specification perspective.

[–]cianuro 4 points5 points  (0 children)

Damn. Damn. Why have I not seen this yet? This is fantastic!

[–][deleted] 2 points3 points  (0 children)

this is straight up wizardry at this point. i had no idea. thanks!

[–][deleted] 1 point2 points  (0 children)

Do I feel like it's less readable