When we start learning Python, one of the first concepts we come across is variables. But what exactly are they?
Understanding Variables
A variable is like a container that stores information. Imagine you have a box, and you put something inside it—like a number, a word, or even a list of items. The name of the box is the variable, and the thing inside is the value. In Python, variables don’t need special declarations. You simply assign a value using the = sign, and Python will take care of the rest
Think of it like this: You have a jar, you put candies inside it and stick a label on the jar called candies. Now, whenever you want to know how many candies you have, you just look at candies.
Key Points About Variables in python
Dynamic Typing: Unlike some other languages, you don't need to specify a variable's type. Python automatically figures it out based on the value you assign to it (e.g., a number, a string, etc.).A Label, Not a Box: A variable in Python is a label or a name tag that points to a specific value stored in your computer's memory. When you change the variable's value, you're just pointing the label to a new location in memory.
Variable Naming Rules:
- Names can contain letters, numbers, or underscores (_).
- They must start with a letter or an underscore.
- They cannot start with a number.
- You cannot use any of Python's reserved keywords (like for, if, class, def, while, etc.) as a variable name.
.png)
Comments
Post a Comment