Variables in Python can hold text and numbers. A program can have one or more variables. For instance, the program below creates 3 variables:
x = 2
In the example above, we have three variables: x, price and word.
These are the variable rules:
- Variables may not contain spaces or special characters (!@#$%^&*).
- Variable names are on the left and their values on the right
- Once a variable is assigned, it can be used in other places of the program.
Text variables may be defined in 3 ways:
word = 'Hello'
Once defined variables can be replaced or modified:
x = 2
The first output of the program above is simply the raw value of the variables.
If you want to print a more detailed message like:
"x = 5", use the line 'print("x = " + str(x))'.
This str() function converts the numeric variable to text.