What are variables in Python?
One of the things that I found when teaching Python at GCSE level is starting off with the topic, it is essential to introduce the topic of variables. This is vital, as variables are one of the building blocks in not only Python but programming in general. The thing was, teaching it to people who had no idea of how to program was quite challenging.
How do you describe what a variable is to someone very new to programming? Not only that, but how does one show newcomers to programming how a variable would be used in a meaningful way? A variable is a way of storing a value in the computer’s memory — great and true, but that does not excite me to want to learn more about it, nor does it give me much information; I need examples. That is where the teaching starts.
The generic way of defining a variable is by calling it x. I am not going to do that; why? Because that is the least meaningful value that I can think of. It does not help someone to learn to program; it adds to the confusion. Let’s try something more meaningful; why not ‘myName’.
myName is a good variable name because it is easy to know that this is going to be given the value of someone’s name. It shows that the purpose of a variable is to contain information and the most important thing is that this information can change. Soemone’s name is not likely to change, but adding more users into the mix can mean that the variable will change depending on who puts their name in.