Hacker News new | ask | show | jobs
by rodorgas 1945 days ago
There’s a nice syntactic sugar for debugging with f-strings: if you place an equal sign, it will print both the variable name and the value. For example:

    >>> f"{name=}"
    'name=Rodrigo'
2 comments

Thanks for bringing attention to this! That has bugged me a lot when debugging in different languages and I only stumbled over it recently when reading the Python docs.
I don't know how I missed this, I love it, thank you.
> I don't know how I missed this

It wasn’t added until Python 3.8 (f-strings were new in 3.6).

That makes sense. The big f-string tutorial people reference (and is the current top result on DuckDuckGo for "f-string") was written prior to 3.8.