Arithmetic Operators
Arithmetic operators are used for performing mathematical operations.
+
: Addition-
: Subtraction*
: Multiplication/
: Division%
: Modulus (remainder)**
: Exponentiation//
: Floor Division (quotient, rounded down to the nearest whole number)
Comparison Operators
Comparison operators are used to compare values.
==
: Equal to!=
: Not equal to>
: Greater than<
: Less than>=
: Greater than or equal to<=
: Less than or equal to
Logical Operators
Logical operators are used to combine or modify Boolean values.
and
: Logical AND (True if both operands are True)or
: Logical OR (True if at least one operand is True)not
: Logical NOT (inverts the Boolean value)
Assignment Operators
Assignment operators are used to assign values to variables.
=
: Assigns the value on the right to the variable on the left+=
: Adds the right operand to the left operand and assigns the result to the left operand-=
: Subtracts the right operand from the left operand and assigns the result to the left operand*=
: Multiplies the left operand by the right operand and assigns the result to the left operand/=
: Divides the left operand by the right operand and assigns the result to the left operand%=
: Computes the modulus of the left operand and the right operand and assigns the result to the left operand**=
: Calculates the exponentiation of the left operand by the right operand and assigns the result to the left operand//=
: Performs floor division on the left operand by the right operand and assigns the result to the left operand:=
(Walrus Operator): Assigns a value to a variable as part of an expression
Bitwise Operators
Bitwise operators perform operations on binary representations of numbers.
&
: Bitwise AND|
: Bitwise OR^
: Bitwise XOR (exclusive OR)~
: Bitwise NOT (complement)<<
: Left Shift>>
: Right Shift
Membership Operators
Membership operators are used to test if a value is present in a sequence.
in
: Returns True if a value is found in the sequencenot in
: Returns True if a value is not found in the sequence
Identity Operators
Identity operators are used to compare the memory location of two objects.
is
: Returns True if both variables point to the same objectis not
: Returns True if both variables point to different objects
Reference: