

Python operators
Presentation
•
Arts
•
2nd Grade
•
Practice Problem
•
Easy
s tobgyal
Used 25+ 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
Try it.....
26
Python operators
Show answer
Auto Play
Slide 1 / 26
SLIDE
Similar Resources on Wayground
20 questions
TOÁN LỚP 2 TUẦN 5 KẾT NỐI TRI THỨC
Presentation
•
2nd Grade
22 questions
T/A O LA P/A
Presentation
•
KG
19 questions
FRACCIONES
Presentation
•
3rd Grade
20 questions
REPASO 1
Presentation
•
2nd Grade
18 questions
Perfect Squares Recap
Presentation
•
6th Grade
20 questions
Nuevo Realismo
Presentation
•
1st - 3rd Grade
19 questions
TABLAS DE MULTIPLICACIÓN
Presentation
•
2nd Grade
18 questions
Cuestionario Iliana B. 2do Quimestre
Presentation
•
2nd Grade
Popular Resources on Wayground
20 questions
"What is the question asking??" Grades 3-5
Quiz
•
1st - 5th Grade
20 questions
“What is the question asking??” Grades 6-8
Quiz
•
6th - 8th Grade
10 questions
Fire Safety Quiz
Quiz
•
12th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
34 questions
STAAR Review 6th - 8th grade Reading Part 1
Quiz
•
6th - 8th Grade
20 questions
“What is the question asking??” English I-II
Quiz
•
9th - 12th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
47 questions
8th Grade Reading STAAR Ultimate Review!
Quiz
•
8th Grade
Discover more resources for Arts
20 questions
"What is the question asking??" Grades 3-5
Quiz
•
1st - 5th Grade
10 questions
Odd and even numbers
Quiz
•
1st - 2nd Grade
17 questions
2nd Grade Graphs (Bar & Picture)
Quiz
•
2nd Grade
15 questions
Telling Time
Quiz
•
2nd Grade
14 questions
Main Idea
Quiz
•
2nd - 3rd Grade
16 questions
Counting Coins counting money
Quiz
•
1st - 2nd Grade
15 questions
2.9G Telling Time to the Minute: set 3
Quiz
•
2nd - 3rd Grade
19 questions
Fire Safety
Quiz
•
KG - 2nd Grade