Professional Documents
Culture Documents
ITE3711 Lecture1.3 Operators 20230906
ITE3711 Lecture1.3 Operators 20230906
ITE3711 Lecture1.3 Operators 20230906
Part 3 :
Operators
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators
2
Lecture 1 – Part 3
Arithmetic operators
Arithmetic operators are used with numeric values to perform common mathematical operations
Arithmetic operators
4
Lecture 1 – Part 3
Arithmetic operators
Example of * multiplication,
/ division, Example Result
** superscripts, print(5 * 5) 25
print(5.0 * 5.0) 25.0
// integer division,
print(5 ** 4) 625
and % remainder
print(5 / 5) 1.0
print(5.0 / 5.0) 1.0
print(5 / 4) 1.25
print(5 // 4) 1
print(4 % 4) 0
5
print(5 % 4) 1
Lecture 1 – Part 3
Arithmetic operators
6
Lecture 1 – Part 3
Assignment operators
7
Lecture 1 – Part 3
Assignment operators
Example of =, += and -=
Operator Example Result
= x=5 5
print(x)
+= x=5 10
x += 5
print(x)
-= x=5 0
x -= 5
print(x)
8
Lecture 1 – Part 3
Assignment operators
9
Lecture 1 – Part 3
Comparison operators
Logical operators
11
Lecture 1 – Part 3
Logical operators
Truth table
Condition 1 Condition 2 and or
result result
True True True True
True False False True
False True False True
False False False False
Condition not
result
True False
12
False True
Lecture 1 – Part 3
number1 = 5
number2 = 10
sum = number1 + number2
print(sum) Output:
print("The sum of two numbers: " + str(sum)) 15
The sum of two numbers: 15
13
Lecture 1 – Part 3
print(sum)
print("The sum of two numbers: " + str(sum))
number1 = 15
Update the value of variable – number1 and number2
number2 = 20
sum = number1 + number2
print(sum)
print("The sum of two numbers: " + str(sum))
14
Lecture 1 – Part 3
print(sum)
print("The sum of " + str(number1) + " and " + str(number2) + " is " + str(sum))
print(sum)
print("The sum of " + str(number1) + " and " + str(number2) + " is " + str(sum))
15
Lecture 1 – Part 3
print(sum)
print("The sum of " + str(number1) + " and " + str(number2) + " is " + str(sum))
print(sum)
print("The sum of " + str(number1) + " and " + str(number2) + " is " + str(sum))
16
Lecture 1 – Part 3
print(name + " can play the roller coaster? " + str(height>145 and height<180))
17
Lecture 1 – Part 3
18