Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

"Mastering Python Operators: A Comprehensive Guide to Arithmetic, Comparison, Logical, Assignment, and More"

Rating
-
Sold
-
Pages
9
Uploaded on
30-04-2023
Written in
2022/2023

Arithmetic Operators: These are used to perform arithmetic operations such as addition, subtraction, multiplication, division, and modulo. For example, the operator + is used for addition, the operator - is used for subtraction, the operator * is used for multiplication, the operator / is used for division, and the operator % is used for modulo. Comparison Operators: These are used to compare two values or variables and return a Boolean value (True or False). Some commonly used comparison operators include == (equal to), != (not equal to), (less than), (greater than), = (less than or equal to), and = (greater than or equal to). Logical Operators: These are used to perform logical operations such as AND, OR, and NOT on Boolean values. The operator and is used for AND, the operator or is used for OR, and the operator not is used for NOT. Bitwise Operators: These are used to perform bitwise operations on binary numbers. Some commonly used bitwise operators include & (AND), | (OR), ^ (XOR), ~ (NOT), (left shift), and (right shift). Assignment Operators: These are used to assign values to variables. For example, the operator = is used to assign a value to a variable, the operator += is used to add a value to a variable and then assign the result to the same variable, and so on.

Show more Read less
Institution
Course

Content preview

Python Operators
Operators in python are constructs in Python that instruct the interpreter
to perform a certain function; however, these are traditionally not defined
as functions; rather, they are syntactically and semantically different from
functions. Operators are used to performing operations on variables and
values according to their use.
Python language supports the following types of operators.

1. Arithmetic Operators
2. Bitwise Operators
3. Membership Operators
4. Identity Operators
5. Comparison Operators
6. Assignment Operators
7. Logical Operators
1. Arithmetic Operator
Arithmetic operators are used to performing mathematical operations

Operator Description Syntax Output

+ Addition a+b Returns sum of the operands

– Subtraction a-b Returns Difference of the operands

/ Division a/b Returns Quotient of the operands

* Multiplication a*b Returns product of the operands

** Exponentiation a**b returns exponent of a raised to the
power b

% Modulus a%b returns remainder of the division

// Floor division a//b returns a real value and ignores the
decimal part

, Let us consider an example program for carrying out the arithmetic
operations explained above.


Xa = int(input('Enter First number: '))
Xb = int(input('Enter Second number: '))
add = Xa + Xb
diff = Xa - Xb
mul = Xa * Xb
div = Xa / Xb
floor_div = Xa // Xb
power = Xa ** Xb
modulus = Xa % Xb
print('Sum of the numbers is',Xa ,'and' ,Xb ,'is :',add)
print('Difference of the numbers is ',Xa ,'and' ,Xb
,'is :',diff)
print('Product of the numbers is ' ,Xa ,'and' ,Xb ,'is :',mul)
print('Division of the numbers is ',Xa ,'and' ,Xb ,'is :',div)
print('Floor Division of the numbers is ',Xa ,'and' ,Xb
,'is :',floor_div)
print('Exponent of the numbers is ',Xa ,'and' ,Xb
,'is :',power)
print('Modulus of the numbers is ',Xa ,'and' ,Xb
,'is :',modulus)



2. Bitwise Operators
Refers to the operators working on a bit, i.e. they treat the operand as a

string of bits; for example, in bitwise operations, 5 will be considered as

0101.

The box below provides the bitwise operators in python

Written for

Institution
Course

Document information

Uploaded on
April 30, 2023
Number of pages
9
Written in
2022/2023
Type
Class notes
Professor(s)
Student
Contains
All classes

Subjects

$8.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
ajijnadaf

Also available in package deal

Get to know the seller

Seller avatar
ajijnadaf Shri shahaji chhatrapati mahavidya
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions