The or Keyword
Combine conditions with or.
1likes_cats = True
2likes_dogs = False
3if likes_cats or likes_dogs:
4 print("You like animals!")
$ python3 main.py
You like animals!
Every line, explained
likes_cats = True- A boolean is a value that can only be True or False, and in Python both words must start with a CAPITAL letter. Writing true or false is an error.
likes_dogs = False- A boolean is a value that can only be True or False, and in Python both words must start with a CAPITAL letter. Writing true or false is an error.
if likes_cats or likes_dogs:- if checks the condition after it. Two things to notice: the line ends with a colon :, and the lines that belong to the if are indented 4 spaces underneath. Python uses indentation to know exactly which code is "inside" the if. If the condition is True the indented code runs; otherwise Python skips it. (The editor indents for you here; in a real editor you would type the 4 spaces.) Python uses the plain English word or (some languages write ||). The whole condition is True if at least one side is True, and True or False is True.
print("You like animals!")- print(...) shows whatever is inside its round brackets in the terminal, then moves to a new line. It is written all in lowercase, and it needs both brackets.