A = 200
B = -140
C = 400
D = -260
if A < 0:
v1 = 0
else:
v1 = A
if B < 0:
v2 = 0
else:
v2 = B
if C < 0:
v3 = 0
else:
v3 = C
if D < 0:
v4 = 0
else:
v4 = C
What is the shorthand implementation for the above code structure.?
Is there a better / elegant / convenient way to do this?
If you prefer to use the
maxfunction to the python ternary operator, it would look like:However, if you’re planning on having all of these variables treated the same, you might want to consider putting them in a list/tuple in the first place.