Operators in Python

 Operators in Python

Python supports a wide range of operators that can be classified into several categories, including arithmetic, comparison, logical, assignment, bitwise, membership, and identity operators. Below is a comprehensive list of operators in Python:


Arithmetic Operators:


1. `+` (Addition)

2. `-` (Subtraction)

3. `*` (Multiplication)

4. `/` (Division)

5. `//` (Floor Division)

6. `%` (Modulus)

7. `**` (Exponentiation)


Comparison Operators:


8. `==` (Equal to)

9. `!=` (Not equal to)

10. `<` (Less than)

11. `>` (Greater than)

12. `<=` (Less than or equal to)

13. `>=` (Greater than or equal to)


Logical Operators:


14. `and` (Logical AND)

15. `or` (Logical OR)

16. `not` (Logical NOT)


Assignment Operators:


17. `=` (Assignment)

18. `+=` (Add and assign)

19. `-=` (Subtract and assign)

20. `*=` (Multiply and assign)

21. `/=` (Divide and assign)

22. `//=` (Floor divide and assign)

23. `%=` (Modulus and assign)

24. `=` (Exponentiate and assign)

25. `&=` (Bitwise AND and assign)

26. `|=` (Bitwise OR and assign)

27. `^=` (Bitwise XOR and assign)

28. `<<=` (Left shift and assign)

29. `>>=` (Right shift and assign)


Bitwise Operators:


30. `&` (Bitwise AND)

31. `|` (Bitwise OR)

32. `^` (Bitwise XOR)

33. `~` (Bitwise NOT)

34. `<<` (Left shift)

35. `>>` (Right shift)


Membership Operators:


36. `in` (Membership - True if value is found in the sequence)

37. `not in` (Membership - True if value is not found in the sequence)


Identity Operators:


38. `is` (Identity - True if both variables are the same object)

39. `is not` (Identity - True if both variables are not the same object)


These operators are used for various purposes in Python, including performing mathematical calculations, comparing values, evaluating logical conditions, assigning values to variables, manipulating bits, checking for membership in a sequence, and verifying object identity. Understanding how to use these operators is essential for programming in Python, as they are the building blocks for creating complex algorithms and logic.


Comments

Popular posts from this blog

Programming in Python