Having problems with variables! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Having problems with variables!

I understand that variables can contain data, but I don’t understand what it means to be changed. Like why would we need to change the variable? Sorry, still new, thank you!

6th Nov 2021, 12:48 PM
Nazareth Briseno
Nazareth Briseno - avatar
6 Answers
+ 11
Consider you wanted to count the number of letters in a word. So you create a variable "num=0". When you see each letter of the word, you have to add 1 to your number so that you get the total number of letters finally. This is a good example of needing to modify variables. Another example, consider you are making an application where you need to store the user's age. As every year passes, you need to add 1 to the user's age right? Here too our variable is changed. As you're new to this, you'll get hang of it once you spent a good amount of time in this and understood some more stuff. My hearty wishes for you 😊
6th Nov 2021, 12:55 PM
Rishi
Rishi - avatar
+ 5
Rishi has provided great examples, in addition to what's been said, for some games where you need to collect in-game currencies or fight monsters, your health and your currencies will have to be changed constantly, another example would be driving a car at different speeds (or forces) Hopefully this would give you some insights
6th Nov 2021, 1:22 PM
Tim
Tim - avatar
+ 3
Programming is much about data management and data manipulation. So when you load the data in the computers memory, you need some kind referens to them. This is what we use the varables for. Some data are static, and will never be changed. In Python they are called inmutable, like integers, strings and tuples. You can assign new data to these variables, but then you will store it on another place in the computers memory, so it is no longer the ’same’ object. Other data structurs are of dynamic type, and can be changed, like lists and dictionaries. Inplace changes of values in these objects will change the object, and not create a new object at another place in the memory. These data structurs are called mutalable objects, and can be a bit tricky to work with, especially if you have multiple references (variables) pointing at the same object. The best way to learn about how different kind of data object acts when you working with them is to try and figure out how they work.
6th Nov 2021, 4:03 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Lokal Toka Rikun what name? Don't post irrelevant comments plz 😊
20th Nov 2021, 1:58 PM
Rishi
Rishi - avatar
- 1
name
20th Nov 2021, 1:14 PM
Lokal Toka Rikun
Lokal Toka Rikun - avatar
- 1
name
20th Nov 2021, 1:15 PM
Lokal Toka Rikun
Lokal Toka Rikun - avatar