Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if else return
#1
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])
Reply
#2
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.
Reply
#3
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.
Reply
#4
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!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020