The C# version might go like:
- Code: Select all
var example = a < b ? ValueC : ValueD
The python one is similar in function but formatted different:
- Code: Select all
var example = ValueC if a < b else ValueD
That one kind of implies that ValueC is the default and ValueD is a backup.
Cobra may already do something like that, but I haven't seen it. I know you can do a two-line if-else using commas, like:
- Code: Select all
if a < b, example = ValueC
else, example = ValueD
(Oddly enough, you don't even have to declare example first. It appears to "leak" out of the if-else scope and be available afterwards).
But I think the one-liner isn't possible.
Would that be a worthwhile addition to the language, and if so which format to go with?