News for hackers. Stuff that matters.
Re:Icecream: Never use print() to debug again in Python by mkl on Tuesday March 30, 2021 @05:48AM (#26632737)
You can also make it a bit prettier by adding spaces:

  >>> print(f"{d['key'][1] = }")
  d['key'][1] = 'one'
It works with any expression you like, not just variables:

  >>> print(f'{np.sin(np.pi/4.) = }')
  np.sin(np.pi/4.) = 0.7071067811865475
Re:Icecream: Never use print() to debug again in Python by amelius on Tuesday March 30, 2021 @06:42AM (#26633046)
> It works with any expression you like

Also assignment expressions? :)

Re:Icecream: Never use print() to debug again in Python by OJFord on Tuesday March 30, 2021 @06:55AM (#26633130)

    >>> print(f"{(yes:='yes')=}")
    (yes:='yes')='yes'
Re:Icecream: Never use print() to debug again in Python by mkl on Tuesday March 30, 2021 @08:03AM (#26633598)
Yep.

  >>> print(f"{(yes:='yes') = } and now {yes = }")
  (yes:='yes') = 'yes' and now yes = 'yes'
Re:Icecream: Never use print() to debug again in Python by wadkar on Tuesday March 30, 2021 @08:25AM (#26633774)
I believe the walrus operator `:=` was introduced in Python 3.8. So keep that it in mind.
Re:Icecream: Never use print() to debug again in Python by L3viathan on Tuesday March 30, 2021 @08:41AM (#26633894)
As was this feature.
Re:Icecream: Never use print() to debug again in Python by wadkar on Wednesday March 31, 2021 @09:55AM (#26647329)
Indeed but the operator is useful beyond fprint
Re:Icecream: Never use print() to debug again in Python by Aeolun on Tuesday March 30, 2021 @08:03AM (#26633599)
Not sure if I would consider that an improvement.