6.7. Boolean Conjunction

6.7.1. Rationale

1 & 1 -> 1
1 & 0 -> 0
0 & 1 -> 0
0 & 0 -> 0

6.7.2. Syntax

>>> True and True
True
>>> True and False
False
>>> False and True
False
>>> False and False
False

6.7.3. Example 1

>>> firstname = 'Mark'
>>> lastname = 'Watney'
>>>
>>> firstname == 'Mark' and lastname == 'Watney'
True

Because:

>>> firstname == 'Mark'
True
>>> lastname == 'Watney'
True

Rule:

>>> True and True
True

6.7.4. Example 2

>>> firstname = 'Mark'
>>> lastname = 'Watney'
>>>
>>> firstname == 'Mark' and lastname == 'Twardowski'
False

Because:

>>> firstname == 'Mark'
True
>>> lastname == 'Twardowski'
False

Rule:

>>> True and False
False

6.7.5. Control Flow

>>> firstname = 'Mark'
>>> lastname = 'Watney'
>>>
>>> if firstname == 'Mark' and lastname == 'Watney':
...     print('Hello Space Pirate')
... else:
...     print('Sorry, astronauts only')
Hello Space Pirate

6.7.6. Assignments