in C (and C family of languages) an expression (4+7, 5+2)
returns 7
. But the same expression in Python would result in a tuple (11, 7)
So does python have a comma operator like C ?
You should use something like this to replace it:
comma_operated = (4+7, 5+2)[-1]
but as noted correctly in the comments, why would you want it? It is used in C or C++ quite seldomly and there are good reasons for that.
AFAIK, no. Though you can always simulate this by using two lines instead of one. :-)
x = (call_one(), call_two())
# is almost the same as
call_one()
x = call_two()
# or
x = (call_one(), call_two())[1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With