lingo.lol is one of the many independent Mastodon servers you can use to participate in the fediverse.
A place for linguists, philologists, and other lovers of languages.

Server stats:

66
active users

#dynamicformatting

0 posts0 participants0 posts today
Dr. Juande Santander-Vela<p>Today I learned combined with Public Service Announcement:</p><p>In Python, you can use format strings with variables not just as the values that need to be represented, but also as parameters for the values!</p><p>I.e., if you want to print a given number in scientific notation, you can do:</p><p>```python<br>&gt; value = 314159265<br>&gt; print(f”{value:6.2e}“)<br>3.14e+06<br>```</p><p>But if you want to personalize the printing in significant digits and floating point digits you can do:</p><p>```python<br>&gt; digits = 12 # total number of digits<br>&gt; fl_digits = 4 # for the floating point part<br>&gt; value = 314159265<br>&gt; print(f"{value:{digits}.{fl_digits}e}")<br> 3.1416e+06<br>```<br><a href="https://astrodon.social/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a> <a href="https://astrodon.social/tags/precision" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>precision</span></a> <a href="https://astrodon.social/tags/NumericPrecision" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>NumericPrecision</span></a> <a href="https://astrodon.social/tags/NumberFormatting" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>NumberFormatting</span></a> <a href="https://astrodon.social/tags/DynamicFormatting" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>DynamicFormatting</span></a> <a href="https://astrodon.social/tags/DynamicNumericPrecision" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>DynamicNumericPrecision</span></a> <a href="https://astrodon.social/tags/TIL" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>TIL</span></a> <a href="https://astrodon.social/tags/PSA" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>PSA</span></a> <a href="https://astrodon.social/tags/TodayILearned" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>TodayILearned</span></a> <a href="https://astrodon.social/tags/PublicServiceAnnouncement" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>PublicServiceAnnouncement</span></a></p>