In this article, we will understand Python variables and Python operators in detail.
Python Variables
In a programming language, variables are fundamental for storing and managing data within a program. Variables act as containers to store values and allow the user to extract and manipulate values as per the requirements of the programmer. Variables store data in storage locations in the computer’s memory.
How to Create Variables?
In Python, you create a variable by assigning a value to a name using the assignment operator =.
Python automatically determines the data type of the variable based on the value assigned.
Variable Naming Rules
- Variable names must start with a letter (a-z, A-Z) or an underscore (_).
- Variables cannot start with a number.
- Variables can only contain alphanumeric characters (letters, numbers) and underscores.
- Variable names are case-sensitive (e.g., num, Num, and NUM are considered different variables).
- Avoid using Python keywords (like from, print, for, while, if, class, etc.) as variable names.
- Any special character is not allowed.
- Space in a variable name is not allowed.
Python Operators
Operators are special symbols in Python that are designed to perform special operations and computations. The value that the operator operates on is called the operand. Some operators require two operands, and some require only one operand to operate. There are seven broad categories of operators used in Python.

1. Arithmetic Operators
Arithmetic Operator | Operator Name | Function |
+ | Addition Operator | Used to add two numbers or two strings. |
– | Subtraction Operator | Used to subtract two numbers. |
* | Multiplication Operator | Used to multiply two numbers. |
/ | Division Operator | Used to divide two numbers and return the quotient. |
% | Modulus Operator | Used to divide two numbers and return the remainder. |
** | Exponent Operator | Gives the value left operand raised to the power of the right operand. |
// | Floordivision Operator | Used to divide two numbers and return the round-off quotient to the nearest integer. |
2. Relational Operators
Relational Operator | Operator Name | Function |
< | Less than | Returns true if the left operand is less than the right. |
> | Greater than | Returns true if the left operand is greater than the right. |
<= | Less than or equal to | Returns true if the left operand is less than or equal to the right. |
>= | Greater than or equal to | Returns true if the left operand is greater than or equal to the right. |
== | Equal to | Returns true if the left operand is equal to the right. |
!= | Not Equal to | Returns true if the left operand is not equal to the right. |
3. Logical Operators
Logical Operator | Operator Name | Function |
and | Logical AND | Returns true if both operands are true. |
or | Logical OR | Returns true if one of the operands is true. |
not | Logical NOT | Returns true if operand is false and returns false when operand is true. |
4. Assignment Operators
Assignment Operator | Operator Name | Function |
= | Assignment | Assigns a value to the variable on the left. |
+= | Assignment Sum | Adds the value on the right to the existing value of the variable on the left. |
-= | Assignment Difference | Subtracts the value on the right from the existing value of the variable on the left. |
*= | Assignment Multiplication | Multiply the value on the right by the existing value of the variable on the left. |
/= | Assignment Division | Divide the existing value of the variable by the value on the right and return the quotient. |
%= | Assignment Modulus | Divide the existing value of the variable by the value on the right and return the remainder. |
**= | Assignment Exponent | Gives the value left operand raised to the power right operand. |
//= | Assignment Floordivision | Divide the existing value of the variable by the value on the right and return the rounded-off quotient to a near integer. |
5. Bitwise Operators
Bitwise Operator | Operator Name | Function |
& | Bitwise AND | Follows the truth table of the AND logic gate. |
| | Bitwise OR | Follows the truth table of the OR logic gate. |
~ | Bitwise NOT | Follows the truth table of NOT logic gate. |
^ | Bitwise XOR | Follows the truth table of the XOR logic gate. |
6. Membership Operators
Membership Operator | Operator Name | Function |
‘in’ | ‘in’ Operator | Returns true if the value is found in the sequence(string, list, tuple, set, or dictionary) |
‘not in’ | ‘not in’ Operator | Returns true if the value is not found in the sequence(string, list, tuple, set, or dictionary) |
7. Identity Operators
Identity Operator | Operator Name | Function |
‘is’ | ‘is’ Operator | Returns true if both operands are identical and saved in the same memory location. |
‘is not’ | ‘is not’ Operator | Returns true if both operands are not identical and not saved in the same memory location. |
Conclusion
In this article, we have covered Python variables and Python data operators in detail. Hands-on practice is a must to have a good command of a programming language.
Stay Tuned!!
Learn the Data Types and Data Structures of Python, click on the link below:
Data Science with Python: Basic Data Types
Data Science with Python: Basic Data Structures
Keep learning and keep implementing!!