Python Variables
Variable Names:
- Must start with a letter or an underscore
- Can only contain alpha-numeric characters and underscores (A-z, 0-9, and _)
- Case sensitive (Angle is not the same as angle)
A Variety of Values can be Assigned to Variables
- Use an equal sign
=
to assign a value to a variable
- The variable ALWAYS appears to the left of the equal sign
- Some valid examples:
- Text: angle = "Ninety degrees"
- A number with a decimal point: angle = 90.0
- A number without a decimal point: angle = 90
- A collection: angle = ["Ninety", 90.0, 90]
Which Variable Names Are Legal?
- SayHello
- _goodbye!
- 2For1
- another_variable
- X
- _42
Algebraic Operations with Variables
- Addition
+
- Subtraction
-
- Multiplication
*
- Division
/
- Integer or Floor Division
//
- Examples of an Operation and Assignment
+=
, -=
, *=
, /=
, or //=