Closed Mr0grog closed 3 years ago
Thanks for the tip, Rob! Steve
On Fri, Oct 2, 2020 at 3:37 AM Rob Brackett notifications@github.com wrote:
I was watching @maalvikabhat https://github.com/maalvikabhat's video demo of this notebook today (nice job!) and noticed that some of the text output didn't include commas in the numbers, which would have been nice. It's pretty easy to do when using f-strings, so I went ahead and updated those, and then all the rest of the strings to use them.
Python's f-strings are typically much more readable than string concatenation ("hello " + some_variable + "!"), interpolation ("hello %s!" % (some_variable)), or string.format() ("hello {}!".format(some_variable)) because the variables/expressions are directly inline within the string. They also offer some fancy formatting options that none of the others (except string.format) do. For example, you can add thousands separators to numbers:
x = 6543245>>> f"There were {x:,} results""There were 6,543,245 results"
(More docs on options at: https://docs.python.org/3/library/string.html#formatspec)
It also doesn't hurt that f-strings are faster, CPU-wise, than all other options. ;)
You can view, comment on, or merge this pull request online at:
https://github.com/edgi-govdata-archiving/ECHO-Sunrise/pull/62 Commit Summary
- Use f-strings for nicer formatting
File Changes
- M ECHO-Sunrise.ipynb https://github.com/edgi-govdata-archiving/ECHO-Sunrise/pull/62/files#diff-385721e4067900c7db7bf326baf66e80 (28)
Patch Links:
- https://github.com/edgi-govdata-archiving/ECHO-Sunrise/pull/62.patch
- https://github.com/edgi-govdata-archiving/ECHO-Sunrise/pull/62.diff
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edgi-govdata-archiving/ECHO-Sunrise/pull/62, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF2XQ6LZNPGP2TYASH2CD3SIWUOXANCNFSM4SBRGITQ .
Hi @Mr0grog I'm sorry I missed this. Thank you so much!! I have merged the PR.
I was watching @maalvikabhat's video demo of this notebook today (nice job!) and noticed that some of the text output didn't include commas in the numbers, which would have been nice. It's pretty easy to do when using f-strings, so I went ahead and updated those, and then all the rest of the strings to use them.
Python's f-strings are typically much more readable than string concatenation (
"hello " + some_variable + "!"
), interpolation ("hello %s!" % (some_variable)
), or string.format() ("hello {}!".format(some_variable)
) because the variables/expressions are directly inline within the string. They also offer some fancy formatting options that none of the others (except string.format) do. For example, you can add thousands separators to numbers:(More docs on options at: https://docs.python.org/3/library/string.html#formatspec)
It also doesn't hurt that f-strings are faster, CPU-wise, than all other options. ;)