Operators in python - Python programming for beginners

python programming for beginners , Operators in python
Python Operators

Hello friends, I hope you are well. Now we are going to learn about the operators in Python. Python programming for beginners will help you. let's go ...

Operators in Python

Operators are the constructs which can manipulate the value of operands. Consider the expression a = b + c. Here a, b and c are called operands and +, = are called the operators. The following are the types of operators supported by Python. There are different types of operators. The following are the types of operators supported by Python.

  • Arithmetic Operators
  • Comparison ( Relational ) Operators
  • Assignment Operators
  • Logical Operators
  • Bitwise Operators
  • Membership Operators
  • Identity Operators

1. Arithmetic Operators

Arithmetic operators are used for performing basic arithmetic operations.

Operator Operation Description
+ Addition Adds values on either side of the operator
- Subtraction Subtracts right hand operand from left hand operand
* Multiplication Multiplies value on either side of the operator.
/ Division Divides left hand operand by right hand operand.
% Modulus It returns remainder after division.
** Exponent Performs exponential calculation on operators.
// Floor Division After division it removes the decimal part.

2. Comparison Operators

These operators compare the values on either sides of them and decide the relation among them. They are also called relational operators.

Operator Description
= = If the value of two operands are equal, then the condition becomes true.
!= If the value of two operands are not equal, then condition becomes true.
< If the value of left operand is greater than the value of right operand, then the condition becomes true.
> If the value of left operand is less than the value of right operand, then the condition becomes true.
<= If the value of left operand is greater than or equal to the value of right operand, then the condition becomes true.
>= If the value of left operand is less than or equal to the value of right operand, then the condition becomes true.

3. Assignment Operator

Python provides various assignment operators. Various shorthand operators are also supported by python.

Operator Description
= Assigns values from right side operands to left side operand.
+= It performs addition and assign the result to left operand.
-= It performs subtraction and assign the result to left operand.
*= It performs multiplication and assign the result to left operand.
/= It performs division and assign the result to left operand.
%= It takes modulus using two operands and assign the result to left operand.
**= Performs exponential (power) calculation on operators and assign value to the left operand.
//= It performs floor division on operators and assign value to the left operand.

4. Bitwise Operator

Bitwise operator works on bits and performs bit by bit operation.

Operator Operation Description
& Binary AND Operator copies a bit to the result if it exists in both operands.
| Binary OR It copies a bit if it exists in either operand.
^ Binary XOR It copies the bit if it is set in one operand but not both.
~ Binary Ones Complement It is unary and has the effect of 'flipping' bits.
<< Binary Left Shift The left operand's value is moved left by the number of bits specified by the right operand.
>> Binary Right Shift The left operand's value is moved right by the number of bits specified by the right operand.

5. Logical Operators

Operator Operation Description
and Logical AND If both the operands are true then condition becomes true.
or Logical OR If any of the operands are true then condition becomes true.
not Logical NOT Used to reverse the logical state of its operand.

6. Membership Operator

Python's membership operators test for membership in a sequence, such as strings, lists, or tuples.

Operator Description
in Evaluates to true if the variables on either side of the operator point to the same object and false otherwise.
not in Evaluates to true if it does not finds a variable in the specified sequence and false otherwise.

7. Identity Operator

Identity operators compare the memory locations of two objects.

Operator Description
is Evaluates to true if the variables on either side of the operator point to the same object and false otherwise.
is not Evaluates to false if the variables on either side of the operator point to the same object and true otherwise.

Thank you so much everyone. If you find it useful, don't forget to share it with your friends.

Comments

Popular posts from this blog

Python programming for beginners - Introduction to python programming