Python Operators with Examples

Python operator – Operators can be used to evaluate operations on variables and values.

For example –

Print(10+5)

In this example, we have used “+” operator to add two variables together.

The operators have been divided into the following categories:

  1. Comparison
  2. Arithmetic
  3. Assignment
  4. Identity
  5. Membership
  6. Logical
  7. Bitwise

Comparison drivers – These are used to compare two values. 

     Example – ==, !=, >, <, >=, <=

Arithmetic operators – These are used with numeric values to perform general mathematical operations:

   Example – +, -, *, /, %, etc

Assignment operators – These are used to assign values to variables:

  Example – =, +=, -=, *=, /=, etc

Identity operators – These are used for comparing the objects, not if they are equal, but also if they are actually the same object, with the same memory location/address

  Example – is, is not

Membership Operators – These are used to test if a sequence is presented in an object.

 Example – in, not in

Logical Operators – These are used to combine conditional statements

  Example – and, or, not

Bitwise Operators – These are used to compare (binary) numbers

  Example – &, |, ^, ~, etc

Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *