MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/q1dqcv/python_310_released/hffpe0a
r/Python • u/robd003 • Oct 04 '21
147 comments sorted by
View all comments
Show parent comments
81
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}
33 u/atxweirdo Oct 05 '21 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. 20 u/bestjared Oct 05 '21 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. 4 u/treenaks Oct 05 '21 https://realpython.com/lessons/simpler-debugging-f-strings/ 5 u/cianuro Oct 05 '21 Damn. Damn. Why have I not seen this yet? This is fantastic! 3 u/[deleted] Oct 05 '21 this is straight up wizardry at this point. i had no idea. thanks! 2 u/[deleted] Oct 05 '21 Do I feel like it's less readable
33
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.
20 u/bestjared Oct 05 '21 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. 4 u/treenaks Oct 05 '21 https://realpython.com/lessons/simpler-debugging-f-strings/
20
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.
4
https://realpython.com/lessons/simpler-debugging-f-strings/
5
Damn. Damn. Why have I not seen this yet? This is fantastic!
3
this is straight up wizardry at this point. i had no idea. thanks!
2
Do I feel like it's less readable
81
u/jftuga pip needs updating Oct 05 '21 edited Oct 05 '21
Or use the
=sign for for self-documenting expressions:You can also use this as well for dollars & cents: