Icon
Login    Register          




Most Advanced AI

Generate Code at the speed of Thought

Improve Productivity of Developers



Python Tutorial

Python Operators

Python Operators are special symbols that are used to perform operations on one or more operands. Operators are used to manipulate data and variables, and to control the flow of a program.

Python supports the following types of operators:

1. Arithmetic Operators:

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, division, modulus, and exponentiation.

Examples:

a + b # Addition
a - b # Subtraction
a * b # Multiplication
a / b # Division
a % b # Modulus
a ** b # Exponentiation

2. Comparison Operators:

Comparison operators are used to compare two values and return a boolean value (True or False).

Examples:

a == b # Equal to
a != b # Not equal to
a > b # Greater than
a < b # Less than
a >= b # Greater than or equal to
a <= b # Less than or equal to

3. Logical Operators:

Logical operators are used to combine two or more conditions and return a boolean value (True or False).

Examples:

a and b # Logical AND
a or b # Logical OR
not a # Logical NOT

4. Assignment Operators:

Assignment operators are used to assign a value to a variable.

Examples:

a = 5 # Assign 5 to a
a += 5 # Add 5 to a
a -= 5 # Subtract 5 from a
a *= 5 # Multiply a by 5
a /= 5 # Divide a by 5
a %= 5 # Modulus a by 5
a **= 5 # Exponentiate a by 5

5. Bitwise Operators:

Bitwise operators are used to perform bitwise operations on two operands.

Examples:

a & b # Bitwise AND
a | b # Bitwise OR
a ^ b # Bitwise XOR
~a # Bitwise NOT
a << b # Bitwise left shift
a >> b # Bitwise right shift

6. Identity Operators:

Identity operators are used to compare the memory locations of two objects.

Examples:

a is b # True if a and b have the same identity
a is not b # True if a and b do not have the same identity

7. Membership Operators:

Membership operators are used to test if a value is a member of a sequence (list, tuple, set, or dictionary).

Examples:

a in b # True if a is a member of b
a not in b # True if a is not a member of b


Search Menu



Disclaimer:
Patodia Infotech Private Limited (fastdevai.com) has no responsibility for any text or code generated or for any action taken by you based on the contents provided by this web site. The use of this web site is solely at the user's risk. All the services are provided with the understanding that Patodia Infotech Private Limited or any other person or company associated with this company or website are not responsible for any loss or damage occurring to anybody from any code or contents generated by this website. Please note that text, codes and contents are generated by AI. These are state-of-the-art AI solutions. However, these are AI tools so there is no guarantee of accuracy of any code or contents generated.


Copyright © 2021-2024 Patodia Infotech Private Limited, All Rights Reserved.