Thursday, December 26, 2024

What are the 7 Python operators Logical Arithmetic Assignment Bitwise Comparison Membership Online Classes Project Assignments Guide Help

General Overview

  • Definition: Operators perform operations on variables and values.
  • Example: print(10 + 5)

Categories of Python Operators

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

Details of Each Operator Category

1. Python Arithmetic Operators

  • Operators and their meanings:
    • + (Addition)
    • - (Subtraction)
    • * (Multiplication)
    • / (Division)
    • % (Modulus)
    • ** (Exponentiation)
    • // (Floor division)

2. Python Assignment Operators

  • Assign values to variables:
    • =
    • +=
    • -=
    • *=
    • /=
    • %=
    • //=
    • **=
    • &=
    • |=
    • ^=
    • >>=
    • <<=
    • := (Walrus operator)

3. Python Comparison Operators

  • Compare two values:
    • == (Equal)
    • != (Not equal)
    • > (Greater than)
    • < (Less than)
    • >= (Greater than or equal to)
    • <= (Less than or equal to)

4. Python Logical Operators

  • Combine conditional statements:
    • and
    • or
    • not

5. Python Identity Operators

  • Compare object identity (memory location):
    • is
    • is not

6. Python Membership Operators

  • Test for presence in a sequence:
    • in
    • not in

7. Python Bitwise Operators

  • Compare binary numbers:
    • & (AND)
    • | (OR)
    • ^ (XOR)
    • ~ (NOT)
    • << (Left shift)
    • >> (Right shift)

Python Operator Precedence

  • Defines the order of evaluation in expressions.
  • Precedence order (highest to lowest):
    1. () Parentheses
    2. ** Exponentiation
    3. +x, -x, ~x Unary operations
    4. *, /, //, % Multiplication, division, floor division, modulus
    5. +, - Addition and subtraction
    6. <<, >> Bitwise shifts
    7. & Bitwise AND
    8. ^ Bitwise XOR
    9. | Bitwise OR
    10. Comparisons, identity, and membership operators
    11. not Logical NOT
    12. and Logical AND
    13. or Logical OR

Examples

  1. Parentheses have the highest precedence:

    print((6 + 3) - (6 + 3))  
    
  2. Multiplication is evaluated before addition:

    print(100 + 5 * 3)  
    
  3. Operators with the same precedence are evaluated left to right:

    print(5 + 4 - 7 + 3)  
    

Exercise

What will be the result of the following syntax?

x = 5  
x += 3  
print(x)  

Answer: 8.


💥 YouTube https://www.youtube.com/channel/UCJojbxGV0sfU1QPWhRxx4-A

💥 Blog https://localedxcelcambridgeictcomputerclass.blogspot.com/

💥 WordPress https://computerclassinsrilanka.wordpress.com

💥 Facebook https://web.facebook.com/itclasssrilanka

💥 Wix https://itclasssl.wixsite.com/icttraining

💥 Web https://itclasssl.github.io/eTeacher/

💥 Medium https://medium.com/@itclasssl

💥 Quora https://www.quora.com/profile/BIT-UCSC-UoM-Final-Year-Student-Project-Guide

💥 mystrikingly https://bit-ucsc-uom-final-year-project-ideas-help-guide-php-class.mystrikingly.com/

💥 https://elakiri.com/threads/bit-ucsc-uom-php-mysql-project-guidance-and-individual-classes-in-colombo.1627048/

💥 https://bitbscucscuomfinalprojectclasslk.weebly.com/

💥 https://www.tiktok.com/@onlinelearningitclassso1



No comments:

Post a Comment