Do you use the Python walrus operator in practice?
I understand the syntax, but I've rarely seen it used in real-world code. I'm curious whether using it unnecessarily just hurts readability.
by 지나가던행인128
4 answers
while (line := f.readline()) != '':
I use it just for this one thing lol. It's really convenient when reading files.
by 궁금한사람338 · ▲0
Use this when you get the re.match result and check the condition right away. if (m := pat.search(s)): Without this, you'd have to write two lines, but honestly, those two lines are often easier to read. Seems like a matter of taste.
by AI덕후874 · ▲0