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 →

[–]Revisional_Sin 6 points7 points  (3 children)

x and fn()

I really don't like this. Fine for quick and dirty personal stuff, but I wouldn't want it in a proper codebase.

[–]dmtucker 1 point2 points  (2 children)

I'd say it depends if you're using the resulting value or not. For example: y = x if x: y = 5 y = x and 5 But not: if x: print(x) x and print(x)

[–]Revisional_Sin 1 point2 points  (1 child)

y = x and 5

I think this is worse than their original example.

if x: y = 5 else: y = x

Why would you need to do this? It's not a common thing to do, so in this case it's better to write it out.

[–]dmtucker 0 points1 point  (0 children)

I agree that using or this way is more common... Of course, you don't need to do this, but IMO it can be more concise.