This article is in a continuation of my previous articles:
Variable and data types in Python
Syntax/Example
Variable Datatypes
Figure 1: Syntax and Example for Variable and data types (input)


Figure 2: Syntax and Example for Variable and data types (Output)

Expressions and Statements in Python
Operators in Python

Operators are the most important part of a programming language since they provide and enhance the computational and functional capabilities of a programming language. There are various types of operators available in Python and they are categorized under the following categories.
  1. Arithmetic Operators

    They are used to do arithmetic operations and are as in the following:

    • Modulus (%)
    • Division (/)
    • Multiplication (*)
    • Addition (+)
    • Subtraction (-)
    • Exponent (**)
    • Floor Division (//)

    Syntax and Example

    Arithmetic Operators

    Figure 3: Syntax and Example for Arithmetic Operators (Input)

    Example for Arithmetic Operators

    Figure 4: Syntax and Example for Arithmetic Operators (Output)

  2. Relational/Comparison Operators

    They are used to relate or compare the values on variables present on both sides of these operators. Relational/Comparison operators are as listed below:

    • Equality (==)
    • Not Equal (!=)
    • Less Than (<)
    • Greater Than (>)
    • Less Than Equals (<=)
    • Greater Than Equals (>=)

    Syntax and Example

    Relational Comparison Operators

    Figure 5: Syntax and Example for Relational/Comparison Operators (Input)

    Note: I will explain about Conditional Programming in Python (If statement) used in this example in another article.

    Example for Relational Comparison Operators

    Figure 6: Syntax and Example for Relational/Comparison Operators (Output)

  3. Bitwise Operators

    These operators are also known as Binary Operators. They work on bits and perform bit-by-bit operations and they are listed as in the following:

    • Binary AND (&)
    • Binary OR (|)
    • Binary XOR (^)
    • Binary One's Complement (~)
    • Binary Left Shift (<<)
    • Binary Right Shift (>>)

    Syntax and Example

    Bitwise Binary Operators

    Figure 7: Syntax and Example for Bitwise/Binary Operators (Input)

    Example for Bitwise Binary Operators

    Figure 8: Syntax and Example for Bitwise/Binary Operators (Output)
  4. Logical Operators

    They are used to perform logical operations and are listed below:

    • AND (and)
    • OR (or)
    • NOT (not)

    Syntax and Example

    Logical Operators

    Figure 9: Syntax and Example for Logical Operators (Input)

    Example for Logical Operators

    Figure 10: Syntax and Example for Logical Operators (Output)

  5. Membership Operators

    These operators check for membership in a sequence, such as strings, tuples, dictionary or lists and so on and they are listed as in the following:

    • IS (is)
    • IS NOT (is not)

    Syntax and Example

    Membership Operators

    Figure 11: Syntax and Example for Membership Operators (Input)

    Example for Membership

    Figure 12: Syntax and Example for Membership Operators (Output)

  6. Identity Operators

    These operators are used to compare the memory locations of two objects and they are listed as in the following:

    • IS (is)
    • IS NOT (is not)

    Syntax and Example

    Identity Operators

    Figure 13: Syntax and Example for Identity Operators (Input)

    Example for Identity Operators

    Figure 14: Syntax and Example for Identity Operators (Output)

  7. Assignment Operators

    They are used for assigning values to variables and are listed as in the following:

    • Assignment Operator (=)
    • Modulus AND (%=)
    • Divide AND (/=)
    • Multiply AND (*=)
    • Add AND (+=)
    • Subtract AND (-=)
    • Exponent AND (**=)
    • Floor Division AND (//=)

    Syntax and Example

    Assignment Operators

    Figure 15: Syntax and Example for Assignment Operators (Input)

    Example for Assignment Operators

    Figure 16: Syntax and Example for Assignment Operators (Output)