"Mastering Python Operators: A Comprehensive Guide to Arithmetic, Comparison, Logical, Assignment, and More"
1 view 0 purchase
Course
DSE 505
Institution
Shivaji Univesrsity
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 ...
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.
– 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
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller ajijnadaf. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $8.39. You're not tied to anything after your purchase.