OPERATORS

Python supports a variety of operators, which can be categorized into several types. Here's an overview of some common types of operators in Python:

Arithmetic Operators

+ (addition)

- (subtraction)

* (multiplication)

/ (division)

% (modulo, returns the remainder)

// (floor division, returns the quotient as an integer)

** (exponentiation)

Example

a = 10

b = 3

addition = a + b

division = a / b

remainder = a % b

Comparison Operators

== (equal to)

!= (not equal to)

< (less than)

> (greater than)

<= (less than or equal to)

>= (greater than or equal to)

Example

x = 5

y = 10

is_equal = x == y

is_greater = x > y

Logical Operators

and (logical AND)

or (logical OR)

not (logical NOT)

Example

a = True

b = False

logical_and = a and b

logical_or = a or b

logical_not = not a

Assignment Operators

= (assignment)

+= (addition assignment)

-= (subtraction assignment)

*= (multiplication assignment)

/= (division assignment)

%= (modulo assignment)

//= (floor division assignment)

**= (exponentiation assignment)

Example

x = 5

x += 3  # Equivalent to x = x + 3

Membership Operators

in (checks if a value is present in a sequence)

not in (checks if a value is not present in a sequence)

Example

numbers = [1, 2, 3, 4, 5]

is_present = 3 in numbers

Identity Operators

is (checks if two variables refer to the same object)

is not (checks if two variables do not refer to the same object)

Example

a = [1, 2, 3]

b = a

is_same_object = a is b