Variables store, modify, and reuse information.
Variables are like boxes which contain some item. It is useful to make the label descriptive of what it contains.
Variables in Python are set using =.
fruit = "Pineapple"
print(fruit)Variable Names
There are a few naming rules in Python:
- Only use alphanumeric and underscores
- Cannot start with number
- Use underscore instead of space
- Stick generally to lowercase
- Don’t use built-in keywords
- Short but descriptive
Variable Types
Python is dynamically typed, so variables don’t need an explicit type. To check the type of a variable use type()
- String: Series of characters,
"Hi" - Integer: Whole number,
5 - Float: Decimal number,
5.6 - Boolean: True or false,
True