home.social

#fstrings — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #fstrings, aggregated by home.social.

  1. Today I quickly debugged a hacky automation script I have using a great tip from @mariatta, using = on f-strings 😹

    print(f'{len(divs)=} {len(cat_puzzle_lists)=} {col_len=}')

    output:
    len(divs)=3 len(cat_puzzle_lists)=4 col_len=1.3333333333333333

    Learn more at: youtu.be/SNA2O0NQl_Q

    #python #fstrings #debug

  2. Today I learned that in Python you can print a floating point number with thousands separator and no floating point part with the f-string formatter `:integer_digits,.0f`.

    For instance:

    ```python
    print(f"{1234567891*1.1:15,.0f}")
    ```

    prints ` 1,358,024,680`, while

    ```python
    print(f"{1234567891*1.1:15,f}")
    ```

    prints `1,358,024,680.100000`.

    It also properly rounds up or down numbers, which is great.

    #TIL #TodayILearned #Python #FStrings #FloatingPoint #ThousandsSeparator

  3. Today I learned that in Python you can print a floating point number with thousands separator and no floating point part with the f-string formatter `:integer_digits,.0f`.

    For instance:

    ```python
    print(f"{1234567891*1.1:15,.0f}")
    ```

    prints ` 1,358,024,680`, while

    ```python
    print(f"{1234567891*1.1:15,f}")
    ```

    prints `1,358,024,680.100000`.

    It also properly rounds up or down numbers, which is great.

    #TIL #TodayILearned #Python #FStrings #FloatingPoint #ThousandsSeparator

  4. Today I learned that in Python you can print a floating point number with thousands separator and no floating point part with the f-string formatter `:integer_digits,.0f`.

    For instance:

    ```python
    print(f"{1234567891*1.1:15,.0f}")
    ```

    prints ` 1,358,024,680`, while

    ```python
    print(f"{1234567891*1.1:15,f}")
    ```

    prints `1,358,024,680.100000`.

    It also properly rounds up or down numbers, which is great.

    #TIL #TodayILearned #Python #FStrings #FloatingPoint #ThousandsSeparator

  5. Today I learned that in Python you can print a floating point number with thousands separator and no floating point part with the f-string formatter `:integer_digits,.0f`.

    For instance:

    ```python
    print(f"{1234567891*1.1:15,.0f}")
    ```

    prints ` 1,358,024,680`, while

    ```python
    print(f"{1234567891*1.1:15,f}")
    ```

    prints `1,358,024,680.100000`.

    It also properly rounds up or down numbers, which is great.

    #TIL #TodayILearned #Python #FStrings #FloatingPoint #ThousandsSeparator

  6. Today I learned that in Python you can print a floating point number with thousands separator and no floating point part with the f-string formatter `:integer_digits,.0f`.

    For instance:

    ```python
    print(f"{1234567891*1.1:15,.0f}")
    ```

    prints ` 1,358,024,680`, while

    ```python
    print(f"{1234567891*1.1:15,f}")
    ```

    prints `1,358,024,680.100000`.

    It also properly rounds up or down numbers, which is great.

    #TIL #TodayILearned #Python #FStrings #FloatingPoint #ThousandsSeparator

  7. f-string in f-string is valid too 👀

    ...ef ef ef in ef-string

    #fstrings #pythontoot

  8. Wasn't sure if I could do something like this when debugging with f-strings, but turns out it actually works.

    >>> actual = 1
    >>> expected = 2
    >>> f"{actual == expected=}"
    actual == expected_qty=False

  9. There's more to F-strings than simply sticking in variables into curly braces! Watch my @pyohio talk to learn more!

    youtu.be/SNA2O0NQl_Q

  10. Finding anything about f-strings docs in docs.python.org is hard (and I say this even as a core dev 🤨)

    "F-strings" is like a "common name" that everybody knows now, but...it wasn't its original name.

    First, the PEP for it is (PEP 498) is called "Formatted String Interpolation"

    Then, CPython officially documents this feature not under "f-strings" heading but as "Formatted String Literal"

    😵‍💫 🤕

  11. Made a trailer for my PyOhio talk about my favorite topic: F-strings! 😎

    What do you think? I had so much fun working on it 🙈😝

    Watch the full video at PyOhio. Dec 16, 2023

    pyohio.org/2023/talks/schedule/

    UPDATE: Schedule is now out.
    F-strings! will stream at 2 PM ET/11 AM PT Saturday Dec 16, 2023

  12. Closing out this initial series of posts with one last f-string related nugget which will also be new in 3.12✨

    I really enjoyed creating these and learnt a lot as well! So if you’re keen for more of this sort of content, then definitely drop a follow 🚀

  13. Here’s something new coming to Python 3.12 ✨

    It’s going to make working with f-strings a whole lot nicer!

  14. Another neat trick to enhance the formatting of your text output is to add padding and alignment to it using f-strings! ✨🚀

    See how below👇

  15. The ternary operator in Python is pretty nifty especially when combined with F-strings! ✨🐍

    Here’s how to use it 👇

  16. Turn boring dates into stylish statements with Python’s F-strings! 🚀

    Using F-strings, you can effortlessly format datetime values to suit your needs! 📆✨

    Check it out:

  17. 💡Want to display numbers and currency neatly in Python? F-strings have got your back!

    Give this a try:

  18. I've decided to create a Python programming mastery series which I’m calling 'Python in a Post' 🎉

    The idea is that with each post, the reader will perhaps learn a new Python concept, tip, or trick that can immediately be put into action.

    If you're interested, drop a follow and join me on this journey to Python mastery! 💻🐍