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:
It works with any expression you like, not just variables:
[ Parent
| on HN ]
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.