

Python operators
Presentation
•
Arts
•
2nd Grade
•
Practice Problem
•
Easy
s tobgyal
Used 32+ times
FREE Resource
25 Slides • 1 Question
1
Python operators
2
3
Operators
~special symbols or keywords that perform operations on data values (operands).
~The values that an operator acts on are called operands
Example:
a=20# = operator-----a --> operand
b=30
print(a+b)-->Operator???? operand????
Operators
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Membership operators
Identity operators
Bitwise operators
4
Importance of operators:
~To express computations and manipulate data.
~To control the flow of a program based on conditions.
~To improve efficiency and performance.
~To enable data manipulation and transformation.
~To enhance code readability and expressiveness.
~To facilitate algorithm design and implementation.
5
~Essential for calculations in programs, from simple sums to complex algorithms.
Arithmetic/mathematical operators
6
Example:
x=50
y=7
7
Example 1:
x=100
y=3
print(x%y)
output?????
% (Modulus):
~ Divides left hand operand by right hand operand and returns remainder
8
** (Exponent):
~ Performs exponential (power) calculation on operators..
Example:
x=2
y=5
z=x**y #x raised to the power of y
#same as 2*2*2*2*2
print(z)
Output?????
// (floor division):
~ The division of operands where the result is the quotient in which the digits after the decimal point are removed.
# Example:
x=10
y=3
z=x//y
print(z)
9
hands on practice......
x = 7 y = 3 | |||
SL_No | Expression statement | Answer | Remarks |
1 | x + y |
| Sum of x and y |
2 | x - y |
|
|
3 | x * y |
|
|
4 | x / y |
|
|
5 | x // y |
|
|
6 | x % y |
|
|
7 | x** y |
|
|
10
Comparison operators:
~Also known as relational operators
~are used to compare two values
~Returns true or false based on the validity of the comparison
11
x = 7 y = 3 | ||
SL_No | Comparison statement | Result |
1 | x==y |
|
2 | x!=y |
|
3 | x>y |
|
4 | x<y |
|
5 | x>=y |
|
6 | x<=y |
|
12
13
Assignment Operators:
~used to assign values to variables
~allow us to store and update data in variables efficiently
14
Hands on practice:
use x and y to calculate for the given assignment operators:
x=20
y=3
1. x+=y
2.x-=y
3. x*=y
4. x%=y
5. x/=y
6. x//=y
7. x**=y
15
Open Ended
Write down the differences between the following operators with an example each:
= and ==
/ and //
* and **
16
Answer:
= operator | == operator |
= is an assignment operator and used to assign value to a variable. | is an equal operator and is used to check equality between two operands. |
/ operator | // operator |
is a regular division and returns the remainder as the float data type. | is a floor division and returns the remainder as the int data type. |
* operator | ** operator |
is used for regular multiplication. | is used for represent a number in the power form. |
17
are used to combine conditions (True/False values). They return either True or False.
logical operators
18
Operator | Description | Example | Result |
and | Returns True if both statements are true | 6 > 7 and 6 > 3 | False |
or | Returns True if one of the statement is true | 6 > 7 or 6 > 3 | True |
not | Reverse the result, returns false if the result is true | not (6 > 7) | True |
Logical Operators Example
19
20
21
x, y, z = 10, 15, 7 | |||||
x > y | y > z | x > y and | x > y | not x > y | not y > z |
|
|
|
|
|
|
Activity
22
Identity operator:
are used to check whether two objects or values refer to the same object in memory.
They evaluate the identity of the operands rather than their values.
There are two identity operators:
is
is not
Example:
x=20
y=20
print(x is y)
23
is not:
~Returns True if both variables are not the same object
Example:
x = 20
y = 20
print(x is not y)
Output????
24
Membership operators:
are used to test whether a value or an object is a member of a sequence or a collection.
They evaluate the membership of the operands.
in
not in
Example:
x = [2,4,6]
print( 2 in x)
return true....
Example:
x = [2,4,6]
print( 2 not in x)
Output????
25
26
Python operators
Show answer
Auto Play
Slide 1 / 26
SLIDE
Similar Resources on Wayground
17 questions
Genetics Review Part 2 (Practice)
Presentation
•
6th - 9th Grade
20 questions
Satuan Panjang
Presentation
•
3rd Grade
20 questions
Diseño Gráfico
Presentation
•
1st Grade
22 questions
La centena
Presentation
•
3rd Grade
20 questions
Orden Perceptual
Presentation
•
2nd Grade
18 questions
Shapes 2nd Grade
Presentation
•
2nd Grade
20 questions
DAYS OF THE WEEK - MONTHS OF THE YEAR
Presentation
•
1st - 2nd Grade
21 questions
G2 MID Prep
Presentation
•
2nd Grade
Popular Resources on Wayground
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade
20 questions
Brand Labels
Quiz
•
5th - 12th Grade
Discover more resources for Arts
20 questions
addition facts
Quiz
•
2nd Grade
20 questions
Arrays/Repeated Addition
Quiz
•
2nd Grade
30 questions
Multiplication Facts 1-12
Quiz
•
2nd - 5th Grade
20 questions
Addition and Subtraction facts
Quiz
•
1st - 3rd Grade
21 questions
place value
Quiz
•
2nd - 3rd Grade
15 questions
Local History
Quiz
•
2nd Grade
20 questions
3-Digit Subtraction With Regrouping
Quiz
•
2nd - 3rd Grade
20 questions
Place Value
Quiz
•
KG - 3rd Grade