I Haz Codes

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Menu
is it not and or?

So we know that if statements rely on a condition (true or false) to see if the code inside the if will run or not. However sometimes we may need to use more than one condition or maybe check for the opposite (negative). The code below shows the use of the key word not. This will take any true or false value and invert it. So true becomes false and false becomes true.

a = True
b = False
if not a:
   print "a is true"
else:
   print "a is not true"

There are two ways we can connect conditions together in a if statement. You can use the and keyword and the or keyword. Run the code below to see an example of the and connective.

age = 63
name = "bert"
if age < 40 and name == "bert":
    print "young bert"
if age > 40 and name == "bert":
    print "old bert"

Output: (clear)

Leave a Reply

Your email address will not be published. Required fields are marked *

Information