News for hackers. Stuff that matters.
Re:What's New in Python 3.12 by ziml77 on Wednesday October 18, 2023 @03:13PM (#37933341)
That's something I've wished for a long time that it had. I know you can use exceptions to get similar behavior but it's really ugly and I just generally don't like raising exceptions for cases that aren't actually exceptional (even though I know Python uses exceptions for normal flow with StopIteration).

What's actually a bit odd about Python missing that operator is that its `or` operator acts as a rough equivalent of C#'s null-coalescing (`??`) operator. To me the safe navigation operator goes hand-in-hand with that.

Re:What's New in Python 3.12 by dragonwriter on Wednesday October 18, 2023 @05:06PM (#37934772)
> What's actually a bit odd about Python missing that operator is that its `or` operator acts as a rough equivalent of C#'s null-coalescing (`??`) operator.

Python `or` is C# `||` plus type coercion. It is not even roughly `??` because important non-None Python values are falsey (0, False, empty collections).

Re:What's New in Python 3.12 by ziml77 on Wednesday October 18, 2023 @05:29PM (#37935034)

    > python3 -c 'print(None or "hello")'
    hello
It evaluates to the left if that's truthy otherwise it evaluates to the right, similar to how `??` evaluates to the left if that's non-null otherwise the right.

In C# even if `||` automatically coerced the types, the output will always be a bool.