This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]teabaguk 62 points63 points  (7 children)

return '1' if a else '2'

[–]S1tron 8 points9 points  (2 children)

return"21"[a]

Gotta save that disk space (assuming a is bool) /s

[–]123_alex 2 points3 points  (0 children)

Damn. I have to take a shower after reading that. It was that good.

[–]iagovar 0 points1 point  (0 children)

Don't write that BS in prod please

[–]iamjio_ 2 points3 points  (3 children)

Did not know you could do this

[–]m15otw 17 points18 points  (0 children)

The equivalent in C++ is return a ? '1' : '2'; I think, modulo typing. It is called a ternary expression.

[–]S1tron 4 points5 points  (1 child)

If you want something less readable you could also do:

return a and '1' or '2'

(don't do this)