+ 1
Can someone describe Variables for me
. hi
6 Answers
+ 1
PART ONE:
Let's say you want to store the user's name in Python. You want to do this because you want to use it to greet them at the beginning and later on when you prompt them for their birthday.
How would you do this? You can't hard code their name because you don't know it. What you would do is "name = input('Please enter your name: ')".
This would get their name and store it in the variable "name". So now you can greet them like "print('Hello' + name)". When they enter their name at the beginning, the variable "name" stores what they entered. Then when you reference "name" in the greeting statement, the variable is "replaced" with their name.
Another instance is organization. What if you use the number "100" in your code alot, but one day you want to change all the instances of "100" to "200". You would have to go back to each instance of "100" and replace it with "200". This would be very tiresome and you could forget an instance of "100". Instead you can do "number = 100".
+ 1
PART TWO:
Now instead of writing "100" a bunch of times in your code, you can replace it with "number". Now if you want to change it, you simply have to replace "number = 100" with "number = 200" at the very beginning.
This is just one of many uses for variable. Hope you get it now.
+ 1
thank you so much
0
I don't understand that pg
0
page