Operators tell Python what to do with values.
You can use operators to calculate with numbers, compare values, and combine true/false results. Parentheses can make a longer expression easier to read.
x = 10
y = 3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.333...
print(x // y) # 3
print(x % y) # 1+, -, and * calculate as you expect. / returns a float. // is floor division, and % gives the remainder after division.
10 // 3 # 3For these positive numbers, floor division gives 3. It is not simply removing decimals in every situation: // follows floor division rules, which matter for negative values too.
Assignment is not comparison: = assigns a value to a variable. == asks whether two values are equal and produces True or False.
age = 18
print(age == 18) # True
print(age != 20) # True
print(age > 20) # False
print(age >= 18) # True
print(age < 21) # True
print(age <= 18) # TrueComparison operators such as ==, !=, >, <, >=, and <= always produce True or False.
age = 20
has_ticket = True
print(age >= 18 and has_ticket) # True
print(age < 18 or has_ticket) # True
print(not has_ticket) # Falseand needs both conditions to be true. or needs at least one. not reverses a true/false value. You will use these ideas in Conditions later.
