3 ms·
I'm curious, what about "x && y" is "python-style" ? It's been in nearly all languages, and for decades before python existed.
by hellofunk 8y ago
I'm curious, what about "x && y" is "python-style" ?
It's been in nearly all languages, and for decades before python existed.
- jstimpfle 8y agoIt was not about "x && y" but about the construct from the parent post as a whole. It never uses y in a boolean context, but only as a value. So I was thinking y could be anything. In python this is how it works: >>> 0 and 'asdf' False >>> 3 and 'asdf' 'asdf' >>> 3 and '' '' 'and' and 'or' in python are short-circuited as in e.g. C, but it's even more short-circuited! The "last" component is not evaluated in a boolean context. For a complete evaluation you have to use the expression in an if or while statement or apply the bool() function. I would say it's like a monad, if that helps.
- deleted 8y ago[deleted]
- hellofunk 8y agoWhat you are talking about has nothing to do with short circuiting.
- jstimpfle 8y agoAgreed, bad choice of words. It's only somewhat similar. Maybe "lazy" would be a better term. Whatever, man! I hope it's clear what I meant.
- hellofunk 8y agoIt’s not that you’re unclear, it’s that it is irrelevant to the discussion, as you were talking about a fairly trivial and unrelated language feature — and it is also a feature that exists in many languages, hardly unique to python.
- jstimpfle 8y agoWhatever, man. Maybe it was not totally related. Agreed. Maybe I had a bad day. It started as a single line that wasn't even the point of my comment. Ok?