Variables and Operators
Variables are containers for storing data values. In Python, a variable is created the moment you first assign a value to it.
Variables
Section titled “Variables”Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.
x = 5y = "Zavont"print(x)print(y)Naming Rules
Section titled “Naming Rules”- A variable name must start with a letter or the underscore character.
- A variable name cannot start with a number.
- Variable names are case-sensitive (
age,Age, andAGEare different variables).
Operators
Section titled “Operators”Python divides the operators into the following groups:
Arithmetic Operators
Section titled “Arithmetic Operators”Used with numeric values to perform common mathematical operations:
| Operator | Name | Example |
|---|---|---|
+ | Addition | x + y |
- | Subtraction | x - y |
* | Multiplication | x * y |
/ | Division | x / y |
% | Modulus | x % y |
** | Exponentiation | x ** y |
Assignment Operators
Section titled “Assignment Operators”Used to assign values to variables:
x = 5 # Assign 5 to xx += 3 # Same as x = x + 3Comparison Operators
Section titled “Comparison Operators”Used to compare two values:
x == y # Equalx != y # Not equalx > y # Greater than