Linked Questions

Popular Questions

Can I shorten this very long elif chain?

Asked by At
if p11 == "+":
    loc = 11
elif p12 == "+":
    loc = 12
elif p13 == "+":
    loc = 13
elif p14 == "+":
    loc = 14
elif p15 == "+":
    loc = 15

I need to have the above going from 11 until 55, so it would amazing if i could simplify it. Whatever number comes after the "p" in the variables is what loc is equal to.

And if it is possible can someone explain the reverse?

Related Questions