0% found this document useful (0 votes)
10 views18 pages

Operators in Python

The document provides an overview of operators in Python, defining them as special symbols that perform operations on operands to form expressions. It categorizes operators into several types, including arithmetic, relational, logical, assignment, identity, membership, and bitwise operators, with examples for each type. The document serves as an educational resource for understanding how to manipulate data using these operators in Python.

Uploaded by

sneheart2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views18 pages

Operators in Python

The document provides an overview of operators in Python, defining them as special symbols that perform operations on operands to form expressions. It categorizes operators into several types, including arithmetic, relational, logical, assignment, identity, membership, and bitwise operators, with examples for each type. The document serves as an educational resource for understanding how to manipulate data using these operators in Python.

Uploaded by

sneheart2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

OPERATORS IN

PYTHON
- Sneha singh
- BCA 3rd year
WHAT ARE OPERATORS?
operator
 Operators are special symbols that Value(operand
perform specific operations on one, )
two, or three operands
 Operands and operators together
form expressions. x = 10
 Python provides a rich set of
operators to manipulate data.
Variable
(operand)
TYPES OF
OPERATORS
 Arithmetic Operators
 Relational Operators
 Logical Operators
 Assignment Operators
 Identity Operators
 Membership Operators
 Bitwise Operators
ARITHMETIC OPERATORS
Perform basic mathematical operations.
Operators: Example:
 (+ (Addition) • x+y
 - (Subtraction) • x-y
 * (Multiplication) • x*y
 / (Division) • x/y
 % (Modulus - remainder) x%y
 ** (Exponentiation)  x ** y
RELATIONAL OPERATORS
Compare two values and return a boolean result (true or false).
Operators: Example:
 == (Equal to)  x==y
 != (Not equal to)  x!=y
 > (Greater than)  x>y
 < (Less than)  x<y
 >= (Greater than or equal to)  x>=y
 <= (Less than or equal to)  x<=y
LOGICAL OPERATORS
Combine boolean expressions and return a boolean result.
Operators:
 and (Logical AND): Returns True if both statements are true.
 or (Logical OR): Returns True if at least one statement is true.
 not (Logical NOT): Reverses the result (True becomes False).
ASSIGNMENT OPERATORS
Assign values to variables.
Operators: Example:
 = (Simple assignment)  x = 10 # x is 10
 += (Add and assign)  x += 5 # x becomes 15 (Same as x =
 -= (Subtract and assign) x + 5)
 x -= 3 # x becomes 12 (Same as x =
 *= (Multiply and assign)
x - 3)
 /= (Divide and assign)
 x *= 2 # x becomes 24
 %= (Modulo and assign)
 x /= 4 # x becomes 6.0
BITWISE OPERATORS
Perform operations on individual bits of integers.
Operators: Example:
 & (Bitwise AND) m=5 # Binary: 0101
 | (Bitwise OR) n=3 # Binary: 0011
 ^ (Bitwise XOR)  result = m & n # Binary: 0001 (Decimal: 1)
 ~ (Bitwise complement)
 << (Left shift)
 >> (Right shift)
MEMBERSHIP OPERATORS
Used to test if a sequence (string, list, or tuple) is present in an object.

Operators:
 in: Returns True if a sequence with the specified value is present in
the object.
 not in: Returns True if a sequence with the specified value is NOT
present.

Example:
fruits = ["apple", "banana", "cherry"]
 is_present = “banana" in fruits # Result: True
 is_missing = “pineapple" not in fruits # Result: True
IDENTITY OPERATORS
Perform operations on individual bits of integers.
Operators: Example:
 is: Returns True if both variables  x is y
are the same object.  x is not y
 is not: Returns True if both
variables are not the same object.
THANK YOU

You might also like