Re:Python 3.8.0a1 is now available for testing
by petercooper on Monday February 04, 2019 @12:59PM
(#19078757)
Quick question.. why is a new operator needed? A lot of languages consider regular assignments to be expression as-is, so why couldn't `if result = do_something():` work? (Genuine question, I'm intrigued what the clash is as I rarely use Python.)
[ Parent
| on HN ]
Re:Python 3.8.0a1 is now available for testing
by Zanni on Monday February 04, 2019 @01:05PM
(#19078814)
To reduce the chance of creating an assignment expression when you intended a simple comparison. Yes, there's already a different operator for equality, but it's easy to mistake = for ==. Forcing you to use := makes it a deliberate act, and makes your intention clear to the reader.
Re:Python 3.8.0a1 is now available for testing
by richardwhiuk on Monday February 04, 2019 @01:03PM
(#19078797)
because it's too easy to typo:
`if foo == true:`
as
`if foo = true:`
which results in horrible subtle bugs