Created
April 19, 2015 16:43
-
-
Save Kwpolska/e41a80b200ca0be37561 to your computer and use it in GitHub Desktop.
Python if/elif/else instructions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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