9/10/2019

• in
• and
• or
• not

# in

This operator can be used in several different contexts in python. The examples here involve strings.

string1 in string2 is true if string1 is a substring of string2.

Here are some examples

u_is_a_vowel = 'u' in 'aeiou'
print(u_is_a_vowel)
## True
x_is_a_vowel = 'x' in 'aeiou'
print(x_is_a_vowel)
## False
ei_is_in_vowels = 'ei' in 'aeiou'
print(ei_is_in_vowels)
## True
eo_is_in_vowels = 'eo' in 'aeiou'
print(eo_is_in_vowels)
## False

# and

The english word “and” is a binary operator used between two logical expressions. The resulting logical value is True if both the left and right operands are True, and False otherwise.

Examples:

x = 6
p = x > 3 and x % 3 == 0
print(p)
## True
x = 7
p = x > 3 and x % 3 == 0
print(p)
## False

# or

The english word “or” is a binary operator used between two logical expressions. The resulting logical value is True if either the left, or right, or both operand(s) is(are) True. It is False otherwise.

Examples:

x = 7
p = x > 3 or x % 3 == 0
print(p)
## True
x = 6
p = x > 3 or x % 3 == 0
print(p)
## True
x = 7
p = x < 3  or  x % 3 == 0
print(p)
## False

# not

The english word not is a unary operator placed in front of a logical expression. The resulting logical value is True if the original logical value is False. If the original logical value is True, the resulting logical value is False. The not operator reverses the original logical value.

Examples:

p = 3 > 7
q = not p
print(q)
## True
p = 3 < 7
q = not p
print(q)
## False