In Python, an operator is a special symbol that performs an operation on one or more values, called operands. For example, in 5 + 3, the symbol '+' is an operator and 5 and 3 are operands. Python provides several types of operators for different kinds of operations โ arithmetic, relational (comparison), logical, assignment, bitwise, membership and identity operators. This guide explains each type of operator in Python with examples.
An operator is a symbol that performs an operation on operands.
Python has seven main types of operators.
Arithmetic operators: +, -, *, /, %, **, //.
Relational (comparison) operators give True or False: ==, !=, >, <, >=, <=.
Logical operators: and, or, not.
Membership operators: in, not in (check presence in a sequence).
Identity operators: is, is not (check if two variables refer to the same object).
Logical operators: used to combine conditional statements. and (True if both are true), or (True if at least one is true), not (reverses the result). Example: (5 > 3) and (2 < 4) gives True.
Assignment operators: used to assign values to variables. = (assign), += , -= , *= , /= , %= , **= , //= (compound assignment). Example: x = 5; x += 3 makes x = 8.
Bitwise operators: work on the binary (bit) form of numbers. & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift), >> (right shift). Example: 5 & 3 = 1.
Membership operators: check whether a value is present in a sequence (like a list, string or tuple). in (True if the value is found), not in (True if the value is not found). Example: 'a' in 'apple' gives True; 5 not in [1, 2, 3] gives True.
Identity operators: check whether two variables refer to the same object in memory. is (True if both refer to the same object), is not (True if they do not). Example: if x = [1,2] and y = x, then x is y gives True.
So Python has seven main types of operators: arithmetic, relational, logical, assignment, bitwise, membership and identity.
Python has seven main types of operators: (1) arithmetic operators (+, -, *, /, %, **, //), (2) relational/comparison operators (==, !=, >, <, >=, <=), (3) logical operators (and, or, not), (4) assignment operators (=, +=, -=, etc.), (5) bitwise operators (&, |, ^, ~, <<, >>), (6) membership operators (in, not in), and (7) identity operators (is, is not).
Arithmetic operators perform mathematical calculations. They are + (addition), - (subtraction), * (multiplication), / (division), % (modulus/remainder), ** (exponent/power) and // (floor division). For example, 7 % 2 gives 1 and 2 ** 3 gives 8.
Membership operators (in, not in) check whether a value exists in a sequence such as a list or string โ for example, 'a' in 'apple' is True. Identity operators (is, is not) check whether two variables refer to the same object in memory โ for example, if y = x, then x is y is True.
Logical operators are used to combine conditional (True/False) statements. They are 'and' (True only if both conditions are true), 'or' (True if at least one condition is true), and 'not' (which reverses the result). For example, (5 > 3) and (2 < 4) gives True.
Basic Structure of a C Program
Learn the basic structure of a C program. Understand the use of preprocessor directives (#include), the main() function, and curly braces { }.
Difference Between System Software and Application Software
Learn the exact difference between System Software and Application Software. Understand how Operating Systems run the hardware, while Apps help the user.
What are Tokens in C Language?
Learn about Tokens in C language. Understand the 6 types of C tokens: Keywords, Identifiers, Constants, Strings, Special Symbols, and Operators.
Tuple in DBMS โ Meaning, Example, Degree and Cardinality
A tuple in DBMS is a single row or record of a relation (table). Learn the meaning of tuple, attribute, degree and cardinality with a clear example.
Types of Database Management System (DBMS) โ Explained with Examples
The main types of DBMS are hierarchical, network, relational and object-oriented, plus NoSQL. Learn each type with its structure, advantages and examples.
Turn this guide into revision flashcards, a practice exam, or an AI-generated podcast โ free, no signup required.