Operators in Python
Operators in Python
1
Lesson Learning Outcome
Pass Merit Distinction
P3 Write a program that M3 Use the IDE to manage D3 Evaluate the use of an
implements an algorithm the development process of IDE for development of
using an IDE. the program. applications in contrasted
with not using an IDE.
2
Python Language
3
Features of Python
▪ Scalable: Has a better structure and support for large programs than shell scripting.
4
Basic rules in Python
5
Assigning Values to Variables
6
Standard Data Types
7
Operators & Operands
▪ Arithmetic Operators
▪ Comparison Operators
▪ Logical (or Relational) Operators
▪ Assignment Operators
▪ Conditional (or Ternary) Operators
8
Arithmetic Operators
Assume,
Variable a holds 10
Variable b holds 20
9
Comparison Operators
Assume,
variable a holds 10
variable b holds 20
10
Assignment Operators
11
Operator Precedence
▪ Operator precedence
refers to the priority of
operators.
▪ That is the order in which
they are evaluated.
12
Operator Example 1
Operator Example 1
x=10
y=3 OUIPUT
print("x =",x) x = 10
print("y =",y) y = 3
print("x + y =",x+y) x + y = 13
print("x - y =",x-y) x - y = 7
print("x * y =",x*y) x * y = 30
print("x / y =",x/y) x / y = 3.3333333333333335
print("x % y =",x%y) x % y = 1
print("x // y =",x//y) x // y = 3
print("x ** y =",x**y) x ** y = 1000
x += y
print("After x+=y, now x =",x) After x+=y, now x = 13
13
Lesson Summary
▪ Features of Python
▪ Variables & Assignment
▪ Operators & Operands
▪ Arithmetic Operators
▪ Comparison Operators
▪ Assignment Operators
▪ Operator Precedence
14