In this lesson, we wil learn about...
These are used with numbers to perform mathematical operations.
x = 5
y = 3
print( x + y )
print( x - y )
print( x * y )
print( x / y )
print( x % y )
print( x ** y )
print( x // y )
8 2 15 1.6666666666666667 2 125 1
These work like the arithmetic operators, but variable being assigned is part of the equation.
x = 5
x += 3
print(x)
x = 5
x -= 3
print(x)
x = 5
x *= 3
print(x)
8 2 15
x = 5
x /= 3
print(x)
x = 5
x %= 3
print(x)
x = 5
x **= 3
print(x)
x = 5
x //= 3
print(x)
1.6666666666666667 2 125 1
These are used to compare two values, and always return a bool
. They become more useful when we talk about if...else
and loops later on.
print( 3 == 5 )
print( 3 != 5 )
print( 3 > 5 )
print( 3 < 5 )
print( 3 >= 5 )
print( 3 <= 5 )
False True False True False True
These are primarily used in if...else
and loops to combine multiple expressions.
print( True and False )
print( True or False )
print( not True )
False True False
These are used to test if a sequence is present in an object. Recall that we saw this with strings, and will again with more complex data structures.
print( "e" in "Hello" )
print( "e" not in "Hello" )
True False
not
and
or