0% found this document useful (0 votes)
27 views8 pages

Operators in Python

Operators in Python are used to perform operations on variables and values. There are different categories of operators including arithmetic, comparison, assignment, logical, bitwise, membership, and identity operators. Arithmetic operators are used for mathematical calculations. Comparison operators compare values and return True or False. Assignment operators assign values to variables. Logical operators perform logical operations on Boolean values.

Uploaded by

ahmedshifa59
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)
27 views8 pages

Operators in Python

Operators in Python are used to perform operations on variables and values. There are different categories of operators including arithmetic, comparison, assignment, logical, bitwise, membership, and identity operators. Arithmetic operators are used for mathematical calculations. Comparison operators compare values and return True or False. Assignment operators assign values to variables. Logical operators perform logical operations on Boolean values.

Uploaded by

ahmedshifa59
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
You are on page 1/ 8

4.

Operators in
Python
Made By:

Yadneyesh (Curious Coder) Find More PDFs on Our Telegram Channel


CodWithCurious.com Search Curious_Coder on Telegram

Keywords in Python
Keywords in Python are special words that have specific
meanings and purposes within the Python language.
They are reserved and cannot be used as variable
names or identifiers.

Keywords play a crucial role in defining the structure and


behavior of Python programs.

Keywords are like building blocks that allow us to create


conditional statements, loops, functions, classes, handle
errors, and perform other important operations. They
help in controlling the flow of the program and specify
how different parts of the code should behave.

For example, the if keyword is used to check conditions


and perform specific actions based on those conditions.
The for and while keywords are used to create loops that
repeat a block of code multiple times.
List of all the keywords in Python:

False await else import pass


None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield

3.4 Operators in Python


Operators in Python are symbols or special characters that are
used to perform specific operations on variables and values.
Python provides various types of operators to manipulate and
work with different data types. Here are some important
categories of operators in Python:
Arithmetic operators
Comparison operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
Arithmetic Operators
Arithmetic Operators:
Arithmetic operators in Python are used to perform
mathematical calculations on numeric values. The basic
arithmetic operators include:
Addition (+): Adds two operands together. For example, if
we have a = 10 and b = 10, then a + b equals 20.

Subtraction (-): Subtracts the second operand from the


first operand. If the first operand is smaller than the
second operand, the result will be negative. For example,
if we have a = 20 and b = 5, then a - b equals 15.

Division (/): Divides the first operand by the second


operand and returns the quotient. For example, if we
have a = 20 and b = 10, then a / b equals 2.0.

Multiplication (*): Multiplies one operand by the other.


For example, if we have a = 20 and b = 4, then a * b
equals 80.

Modulus (%): Returns the remainder after dividing the


first operand by the second operand. For example, if we
have a = 20 and b = 10, then a % b equals 0.
Exponentiation (**) or Power: Raises the first operand to
the power of the second operand. For example, if we have
a = 2 and b = 3, then a ** b equals 8.

Floor Division (//): Provides the floor value of the quotient


obtained by dividing the two operands. It returns the
largest integer that is less than or equal to the result. For
example, if we have a = 20 and b = 3, then a // b equals 6.

Comparison Operators:
Comparison operators in Python are used to compare two
values and return a Boolean value (True or False) based on
the comparison. Common comparison operators include:
Equal to (==): Checks if two operands are equal.

Not equal to (!=): Checks if two operands are not equal.

Greater than (>): Checks if the left operand is greater than


the right operand.

Less than (<): Checks if the left operand is less than the
right operand.

Greater than or equal to (>=): Checks if the left operand is


greater than or equal to the right operand.
Less than (<): Checks if the left operand is less than the
right operand.

Greater than or equal to (>=): Checks if the left operand


is greater than or equal to the right operand.

Less than or equal to (<=): Checks if the left operand is


less than or equal to the right operand.

Assignment Operators:
Assignment operators are used to assign values to variables.
They include:
Equal to (=): Assigns the value on the right to the variable
on the left.

Compound assignment operators (+=, -=, *=, /=):


Perform the specified arithmetic operation and assign
the result to the variable.

Logical Operators:
Logical operators in Python are used to perform logical
operations on Boolean values. The main logical operators
are:
Logical AND (and): Returns True if both operands are
True, otherwise False.
Logical OR (or): Returns True if at least one of the
operands is True, otherwise False.

Logical NOT (not): Returns the opposite Boolean value of


the operand.

Bitwise Operators:
Bitwise operators perform operations on individual bits of
binary numbers. Some common bitwise operators in Python
are:
Bitwise AND (&): Performs a bitwise AND operation on the
binary representations of the operands.

Bitwise OR (|): Performs a bitwise OR operation on the


binary representations of the operands.

Bitwise XOR (^): Performs a bitwise exclusive OR operation


on the binary representations of the operands.

Bitwise complement (~): Inverts the bits of the operand.


Left shift (<<): Shifts the bits of the left operand to the left
by the number of positions specified by the right operand.

Right shift (>>): Shifts the bits of the left operand to the
right by the number of positions specified by the right
operand.
Right shift (>>): Shifts the bits of the left operand to the
right by the number of positions specified by the right
operand.

Membership Operators:
Membership operators are used to test whether a value is a
member of a sequence (e.g., string, list, tuple). They include:
In: Returns True if the value is found in the sequence.

Not in: Returns True if the value is not found in the


sequence.

Identity Operators:
Identity operators are used to compare the identity of two
objects. They include:
Is: Returns True if both operands refer to the same object.

Is not: Returns True if both operands do not refer to the


same object.
5. List, Dictionary, Set,
Tuples & Type Conversion
Made By:

Yadneyesh (Curious Coder) Find More PDFs on Our Telegram Channel


CodWithCurious.com Search Curious_Coder on Telegram

Chapter 5 will Be Upload


In Some Days
Find All PDFs in Our Telegram Channels

You might also like