2.1 What is a variable
A variable in programming is a name that holds a value, like a box that you can store something in and refer to later. In Python, a variable is a named reference to a memory location where a value is stored.
We may use variables for:
- Readability and Maintenance - Variables with meaningful names make the code easier to read and understand. Refer to section 2.2 Variable naming for more info.
Example 2.1.1
- Reusability - Storing data in variables allows for reuse of the data without hardcoding values multiple times.
Example 2.1.2
- Dynamic Data Handling - Variables allow programs to handle dynamic data input, making them flexible. User input is addressed in 2.5 Input statement topic.
Example 2.1.3
In summary, variables in programming are essential tools for storing, retrieving, and manipulating data, which enhances code readability, reusability, and overall efficiency.