What is a variable in Python?
- Named Container: Think of a variable as a labeled box that can store a value.
- Storing Data: Variables hold different types of information, like numbers, text, or more complex data structures.
- Changing Values: The value stored in a variable can be changed throughout your program.
Key Points for Exam Notes
- How to Create a Variable:
my_age = 12 # Stores the number 12
name = "Khushi" # Stores the text "Khushi"
- Rules for Naming:
- Must start with a letter or underscore.
- Can contain letters, numbers, and underscores.
- Case-sensitive (
age
andAge
are different).
- Data Types: Variables automatically determine their data type based on the value assigned:
- Numbers (int, float)
- Text (string)
- True/False (boolean)
- Lists, dictionaries, etc.