Operators#
Introduction#
Operators in Python are special symbols and keywords that allow you to perform operations on values and variables. They encompass a wide range of functionalities—from arithmetic and comparison to logical, bitwise, and assignment operations. Mastering these operators is essential for constructing expressive and efficient Python code, as they form the foundation of nearly every computation or decision-making process in your programs. Below, you’ll find concise examples for each operator to help you understand their usage and expected outcomes.
Arithmetic#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Addition |
|
|
|
Division |
|
|
|
Exponentiation |
|
|
|
Floor Division |
|
|
|
Modulo |
|
|
|
Multiplication |
|
|
|
Negation |
|
|
|
Subtraction |
|
|
|
Augmented Arithmetic#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Addition |
|
|
|
Division |
|
|
|
Exponentiation |
|
|
|
Floor Division |
|
|
|
Modulus |
|
|
|
Multiplication |
|
|
|
Subtraction |
|
|
|
Comparison#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Equality |
|
|
|
Inequality |
|
|
|
Greater Than |
|
|
|
Greater Than or Equal |
|
|
|
Less Than |
|
|
|
Less Than or Equal |
|
|
|
Chained Comparison |
|
|
|
Logical#
Name |
Symbol |
Example |
---|---|---|
False |
|
Certain values are defined to be
|
True |
|
Any object that is not explicitly |
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Identity |
|
|
|
Not Identity |
|
|
|
Logical AND |
|
|
|
Logical Negation |
|
|
|
Logical OR |
|
|
|
Conditional Expression |
|
|
|
Sequences (Lists, Tuples, Strings)#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Concatenation |
|
|
|
Slice Assignment |
|
|
|
Slice Deletion |
|
|
|
Slicing |
|
|
Dictionaries (Mappings)#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Indexed Assignment |
|
|
|
Indexed Deletion |
|
|
|
Indexing |
|
|
String Formatting#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
String Formatting |
% |
|
|
Membership#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Containment Test |
|
|
|
Membership Negation (Not In) |
|
|
|
Bitwise#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Bitwise And |
|
|
|
Bitwise Exclusive Or (XOR) |
|
|
|
Bitwise Inversion (NOT) |
|
|
|
Bitwise Or |
|
|
|
Left Shift |
|
|
|
Right Shift |
|
|
|
Augmented Bitwise#
Name |
Symbol |
Operator |
Example |
---|---|---|---|
Augmented Bitwise And |
|
|
|
Augmented Bitwise Exclusive Or (XOR) |
|
|
|
Augmented Bitwise Or |
|
|
|
Augmented Left Shift |
|
|
|
Augmented Right Shift |
|
|
|