General Overview
- Definition: Operators perform operations on variables and values.
- Example:
print(10 + 5)
Categories of Python Operators
- Arithmetic operators
- Assignment operators
- Comparison operators
- Logical operators
- Identity operators
- Membership operators
- 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:
andornot
5. Python Identity Operators
- Compare object identity (memory location):
isis not
6. Python Membership Operators
- Test for presence in a sequence:
innot 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):
()Parentheses**Exponentiation+x,-x,~xUnary operations*,/,//,%Multiplication, division, floor division, modulus+,-Addition and subtraction<<,>>Bitwise shifts&Bitwise AND^Bitwise XOR|Bitwise OR- Comparisons, identity, and membership operators
notLogical NOTandLogical ANDorLogical OR
Examples
-
Parentheses have the highest precedence:
print((6 + 3) - (6 + 3)) -
Multiplication is evaluated before addition:
print(100 + 5 * 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://bitbscucscuomfinalprojectclasslk.weebly.com/
💥 https://www.tiktok.com/@onlinelearningitclassso1

No comments:
Post a Comment