有没有一种方法可以使此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)
答案 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)