Python Forum

Full Version: if else return
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to Python. I am trying to have the following function change the values of certain lines depending on if the lines are populated or not. Please assist if you can. Thanks in advance.



def checkconsent (CF):
	original_consent = CF
	var = CF[0:2]
	var1 = "RY"
	if CF == "RY" or "RN" or "NY" or "NN":
		return var
	else:
	    return var1
CONSENT = aps.checkconsent(line[1491:1493])
CONSENT1 = aps.checkconsent(line[1493:1495])
CONSENT2 = aps.checkconsent(line[1495:1497])
CONSENT3 = aps.checkconsent(line[1497:1499])
CONSENT4 = aps.checkconsent(line[1499:1501])
CONSENT5 = aps.checkconsent(line[1501:1503])
You should probably start by reading this:
https://python-forum.io/Thread-Multiple-...or-keyword

Also you need to let us know exactly what the problem/error is.
I have read the thread, the issue I am having is that if the field I am looking at is blank, the else function does not return var1. The fields remain blank and does not return the "RY" in the field.
You most probably think that
if CF == "RY" or "RN" or "NY" or "NN":
is equivalent to
if CF == "RY" or CF == "RN" or CF == "NY" or CF == "NN": or
if CF in ("RY", "RN", "NY", "NN"):

but the link in Mekire's post explains it is not the case!