Variables and Operators#
Variables#
Variables are reserved memory locations used to store values. The = sign assigns values to variables.
counter = 100 # integer
miles = 1000.0 # floating point
name = "John" # string
Python has the following standard data types:
Numbers
String
List
Tuple
Dictionary
Operators#
Arithmetic Operators#
Operator |
Description |
Example (a=7, b=3) |
|---|---|---|
|
Addition |
|
|
Subtraction |
|
|
Multiplication |
|
|
Division |
|
|
Modulus (remainder) |
|
|
Exponent |
|
|
Floor division |
|
Comparison Operators#
Operator |
Description |
Example (a=7, b=3) |
|---|---|---|
|
Equal to |
|
|
Not equal to |
|
|
Greater than |
|
|
Less than |
|
|
Greater than or equal to |
|
|
Less than or equal to |
|
Note
The <> operator from Python 2 has been removed. Use != instead.
Assignment Operators#
Operator |
Description |
Example |
|---|---|---|
|
Assign |
|
|
Add and assign |
|
|
Subtract and assign |
|
|
Multiply and assign |
|
|
Divide and assign |
|
|
Modulus and assign |
|
|
Exponent and assign |
|
|
Floor divide and assign |
|
Logical Operators#
Operator |
Description |
Example |
|---|---|---|
|
True if both operands are true |
|
|
True if at least one operand is true |
|
|
Reverses the logical state |
|