Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Created April 19, 2015 16:43
Show Gist options
  • Select an option

  • Save Kwpolska/e41a80b200ca0be37561 to your computer and use it in GitHub Desktop.

Select an option

Save Kwpolska/e41a80b200ca0be37561 to your computer and use it in GitHub Desktop.
Python if/elif/else instructions
input = ['foo deinstall 1', 'foo install 2', 'bar install 3', 'bar deinstall 4', 'foo bar 5']
for i in input:
# If the lines start or end with (de)install, you could try startswith/endswith instead.
if 'deinstall' in i:
print("Will deinstall:", i)
elif 'install' in i:
print("Will install:", i)
else:
print("Unrecognized:", i)
# --- output: ---
# Will deinstall: foo deinstall 1
# Will install: foo install 2
# Will install: foo install 3
# Will deinstall: bar deinstall 4
# Unrecognized: foo bar 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment