Python Forum

Full Version: simple if elif conditions in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi There,
I am very much new to Python and to this forum. I am looking for code help.
I have a SAS code as below and I would like to replicate this in Python.
It would be great if you guys can assist me with this.

if Universtiy in ("name1","name2","name3") then Universtiy_Group='Go8 University';
else if University in ("name4","name5") then Universtiy_Group='Eligible Go8 University';
else Universtiy_Group="Others";

Kind regards,
CK
if Universtiy in ("name1","name2","name3"):
    Universtiy_Group = 'Go8 University'
elif University in ("name4","name5"):
    Universtiy_Group = 'Eligible Go8 University'
else:
    Universtiy_Group = "Others"
Note the indentation. While indentation is ignored by SAS, it is part of the syntax in Python.
university = "name1"

if university in ("name1", "name2", "name3"):
    university_group = "Go8 University"
elif university in ("name4","name5"):
    university_group = "Eligible Go8 University"
else:
    university_group = "Others"