0% found this document useful (0 votes)
2 views10 pages

Susmita Ranju 16442724024 Python Programming

The document provides an overview of various operators in Python, including arithmetic, assignment, comparison, logical, identity, membership, bitwise, and the ternary operator. Each type of operator is explained with examples, highlighting their functionality and importance in programming. This information is essential for understanding how to manipulate data and control program flow in Python.

Uploaded by

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

Susmita Ranju 16442724024 Python Programming

The document provides an overview of various operators in Python, including arithmetic, assignment, comparison, logical, identity, membership, bitwise, and the ternary operator. Each type of operator is explained with examples, highlighting their functionality and importance in programming. This information is essential for understanding how to manipulate data and control program flow in Python.

Uploaded by

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

• NAME: SUSMITA RANJU

• ROLLNO.: 16442724024
• REGNO.: 241641010041
• PAPER NAME: PYTHON PROGRAMMING
• PAPER CODE:BCAC-301
• COURSE:BCA
• SEMESTER: 3RD SEMESTER
Operators in Python: An Overview

Operators are fundamental building blocks


in Python, enabling us to perform various
operations on variables and values. They
are essential for data manipulation, logical
comparisons, and controlling program
flow.
Arithmetic Operators: The Foundation of
Calculation
• Arithmetic operators perform mathematical
computations, forming the core of numerical
processing in Python.
• + (Addition), - (Subtraction), * (Multiplication), /
(Division)
• % (Modulus): Returns the remainder of a division
(e.g., 10 % 3 = 1).
• ** (Exponentiation): Raises the first operand to the
power of the second (e.g., 7 ** 2 = 49).
• // (Floor Division): Divides and returns the integer
part of the quotient (e.g., 10 // 3 = 3).
Assignment Operators: Efficient Variable Updates

Simple Assignment
The = operator assigns a value to a variable. For example, x = 10.

Compound Assignments
Operators like +=, -=, *= update a variable's value by performing an operation and then
assigning the result.

Concise Code
These operators simplify expressions. For instance, a += 3 is equivalent to a = a + 3,
making code more readable.
Comparison Operators: Evaluating Relationships

Comparison operators are used to compare


two values and return a Boolean result ==
(Equal to): Checks if two values are the
same (e.g., 5 == 5 returns True).
•!= (Not equal to): Checks if two values are
different (e.g., 5 != 3 returns True).
•> (Greater than), < (Less than), >= (Greater
than or equal to), <= (Less than or equal to).
Logical Operators: Combining Conditions
• not
1 • Reverses the boolean state of the operand (highest
precedence).
• and
2 • Returns True if both operands are true.
• or
3
• Returns True if at least one operand is true (lowest
precedence).
Identity Operators: Checking Object Reference

Is
Returns True if both variables point to the exact same object in
memory.

Is Not
Returns True if both variables do not point to the same object in memory.

Memory Address
Crucially, identity operators differ from comparison (==) which checks for
value equality. is checks for memory address equality.
Membership Operators: Verifying Containment

Membership operators test for the presence of a value within a


sequence (like a string, list, or tuple).

•in: Returns True if the specified value is found in the sequence.

•not in: Returns True if the specified value is not found in the
sequence.

'apple' in 'pineapple' returns True


5 not in [1, 2, 3] returns True
Bitwise Operators: Manipulating Bits

• Bitwise operators perform operations directly on the individual bits of integer values. They are commonly used in low-level
programming, data compression, and encryption.

Operator Description Example

& Bitwise AND 5 & 3 = 1 (0101 & 0011 = 0001)

| Bitwise OR 5 | 3 = 7 (0101 | 0011 = 0111)

^ Bitwise XOR 5 ^ 3 = 6 (0101 ^ 0011 = 0110)

~ Bitwise NOT ~5 = -6

<< Left Shift 5 << 1 = 10

>> Right Shift 5 >> 1 = 2


Ternary Operator: Concise Conditional Expressions

The ternary operator, or conditional expression, provides a compact way to evaluate


an if-else statement on a single line. It was introduced in Python 2.5.

result = value_if_true if condition else value_if_false

This operator is especially useful for assigning a variable based on a simple condition,
leading to more concise and readable code.

You might also like