Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Introduction To Operators in Python

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Introduction To Operators in Python

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Introduction to

Operators in Python

Python operators are symbols that perform specific operations on one or more
operands. They are fundamental for writing logical and mathematical expressions
in Python programs. This section provides an overview of the main operator
types and their usage.

by Sajida Soomro
Table of Contents

1 Arithmetic Operators 2 Comparison Operators


Learn how to perform basic mathematical Understand how to compare values and make
operations in Python using +, -, *, /, and more. decisions based on the results using <, >, ==,
and other relational operators.

3 Logical Operators 4 Bitwise Operators


Explore the powerful boolean logic of and, or, Discover how to manipulate individual bits in
and not operators to combine multiple binary representations using bitwise operators
conditions. like &, |, ^, and ~.
Arithmetic Operators
1.Addition (+): Adds two operands. Example: 3 + 5 equals 8.

2.Subtraction (-): Subtracts the second operand from the first. Example: 7 - 4 equals 3.

3.Multiplication (*): Multiplies two operands. Example: 2 * 6 equals 12.

4.Division (/): Divides the first operand by the second. Example: 10 / 2 equals 5.0.

5.Modulus (%): Returns the remainder of the division of the first operand by the second. Example: 10 % 3 equals 1

6.Exponentiation () or Power Operator**: Raises the first operand to the power of the second. Example: 2 ** 3 equals 8.
Examples
Comparison (Relational) Operators

Less Than (<)


Equal To (==)
Checks if the left operand is less than the right
operand. Checks if the two operands are equal.

1 2 3

Greater Than (>)


Checks if the left operand is greater than the right
operand.
Examples
Boolean Operators
Boolean operators, also known as logical
operators, are used to combine or modify
Boolean values (True or False).
There are three main Boolean operators in
Python:

AND (and) OR (or)


Returns True if both operands are True, Returns True if at least one of the operands
otherwise False. is True, otherwise False.

NOT (not)
Reverses the logical state of its operand. True becomes False, and False becomes True.
Examples
Bitwise Operators
AND (&)
Performs a bitwise AND operation on each pair of corresponding bits.

OR (|)
Performs a bitwise OR operation on each pair of corresponding bits.
Examples
Sajida Soomro

You might also like