Understanding Variables
Think of a variable as a labeled box where your program stores information. In Python, we create a variable using the assignment operator =. The name goes on the left, and the value goes on the right. That value can be a number, text (inside quotes), or other data. For example, age = 25 means we’re storing the number 25 inside a box called age. The beauty of variables? Their values can change later in the program — they’re flexible!
Python treats uppercase and lowercase letters differently, so CLASS and Class are two completely different variables. But beware — you cannot use reserved keywords like class as variable names because Python already owns them.
Variables follow simple naming rules: start with a letter or underscore, avoid spaces, and don’t begin with numbers. Names like age2, marks, or user_name are valid and readable.
When we print "age" (with quotes), Python displays the word age. But when we print age (without quotes), Python shows the stored value. Small difference, big meaning!
We can even check what type of data a variable holds using type(). And with id(), Python reveals the memory address of the stored value. Interestingly, if two variables store the same immutable value (like x = 10 and y = 10), Python may point both to the same memory location to save space. But once you update x = 20, it gets a new memory reference while y still points to 10.
In short, variables are the foundation of programming — they store, update, and manage data, making your programs dynamic and smart//
SO BASICALLY WE DID A EXPERIMENT ON VARIABLE, TO EAGERLY LEARN ABOUT MORE PLEASE DO FOLLOW AND CONTINUE YOUR JOURNEY WITH ME
#python #Day4 #DataScience #bhartiinsan
Top comments (0)