如果陈述简单

时间:2019-10-25 19:14:45

标签: python if-statement variables var

有没有一种方法可以使此ELIF语句更简单,使此代码不起作用。 更改的变量是APPOINTMENT

elif (rut == '80010900-0' and agental_launch != "" and 'TAL'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'IQQ'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'ANF'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'MJS'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'QTV'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'SVE'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'PMC'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'CHB'  in appointment):
        df.at[idx,'REBATE'] = round(int(monto_neto)*0.35)

2 个答案:

答案 0 :(得分:1)

any用于最后一个变成单线的条件:

elif rut == '80010900-0' and agental_launch != "" and any(x in appointment for x in ['TAL','IQQ','rest of strings to match...']):

答案 1 :(得分:1)

您可以这样做:

elif rut == '80010900-0' and agental_launch != "" and any(elem in appointment for elem in ['TAL','IQQ','ANF','MJS','QTV','SVE','PMC','CHB']):
     df.at[idx,'REBATE'] = round(int(monto_neto)*0.35)