Description

Operator is a symbol that tells the computer to perform the mathematical and logical operation in Python Programming.

Types of Operators:

Python programming language has supports the following operators.

  • Arithmetic Operators
  • Comparison / Relational Operators
  • Logical Operators
  • Assignment Operators
  • Bitwise Operators
  • Membership Operators
  • Identity Operators

Arithmetic Operators in Python Programming

Let's Assume that variable 'a' holds 5 and variable 'b' holds 2, then

Operator Description Example
Addition (+) Adds values on either side of the operator. a + b = 7
Subtraction (-) Subtracts right hand operand from left hand operand. a - b = 3
Mutliplication (*) Multiplies values on either side of the operator.

a * b = 10

Division (/) Divides one operator to another operator. a / b = 2.5
Modulus (%) remainder of a divided by b. a % b = 1
Exponent (**) Performs expontial (power) calculation on operators. a**b = 25
// Floor Division - operands where the result is the quotient in which the digits after the decimal point are removed. a//b = 2

Relation Operators in Python Programming

The Relational Operator are used to compare the values between variables. Relational Operators tabel below...

Operator Description Example
== If the both values are equal, then condition is true. (a==b) is not true
!= If the both values are not equal, then condition becomes true. (a!=b) is true.
> Greater Than ( if the left operand is greater than the right operand, then condition becomes true.) (a > b) is true.
< Less Than ( if the left operand is less than the right operand, then condition becomes true.) (a<b) is true.
<= Less than or Equal to (a <= b ) is not true.
>= Greater than or Equal to (a >= b) is true.

Assignment Operators in Python Programming.

The assignment operator is represented by the equal sign(=). The variable appearing on the left side of = sign and it is assignment the value appearing on the right side of this sign.

 

Operator Expression Example
= a = a + b a = 7
+= a += b a = a + b = 7
-= a -= b a = a - b = 3
/= a /= b a = a / b = 2.5
%=  a %= b a = a % b = 1
*= a *= b  a = a * b = 10
**= a **=b  a = a**b = 25
//= a //= b a = a//b = 2

Logical Operator in Python Programming.

The Logical Operator is used for when we want to check the condition and for making the decisons in Programs.

Operators Description Example
and Logical AND If the both operands are true then condition becomes true. (a and b) is true.
or Logical OR If any of the two operands are non-zero then condition becomes true. (a or b) is true.
not Logical NOT Used to reverse the logical state of its operand. not(a and b) is false

Bitwise Operator in Python Programming.

The Bitwise Operator is special operators which are used for manipulation of the data at bit level. These operator are used for testing the bits, or shifting them right or left. Bitwise operators many not be applied to float or double.

Operator Meaning
& bitwise AND
| bitwise OR
^ bitwise exclusive OR
<< shift left
>> shift right

Python Membership Operators.

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

Operator Description Example
in Evalutes to true if it finds a variable in the specified sequence and false otherwise. a in b, here in results in a 1 if x is a member of sequence y.
not in Evaluates to true if it does not finds a variable in the specified sequence and false otherwise. a not in y, here not in results in 1 if a is not a member of sequence b.

Python Identity Operators.

Operator Description Example
is Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. a is b, here is results false.
is not Evaluates to false if the variables on either side of the operator point to the same object and true otherwise. a is not b, here is not results is true.

 

Comments

Login is mandatory to comment Please login

Recommended Posts

All About of String in Python Programming language

In Python It is called a string which is inside single or double quotation marks. We can write multiline string inside three single or double quotation mark.

List and Tuple in Python Programming

List is a kind of data structure in Python which is mutable, changeable, ordered sequence. Tuples are used to store multiple items in a single variable.

Dictionary In Python | Method Of Dictionary

Dictionary is used to store data values in Key: Value pairs. A dictionary is a collection which is ordered, Changeable and do not allow duplicates.

Implement of All Method of String in Python Programming language

Implementation of all methods of string in python. How to implement of method on string.

Operators based Exercise 1 in Python Programming language.

All operators used for better understanding the python operators.

Sets in Python | Perform Set methods

A Set is an unordered collection data type which does not contain duplicates elements. A set is iterable and mutable data type.