Lecture 2: Variables — Concept

Syed Faizan
PythonForKids
Published in
3 min readDec 20, 2018

In most or all software programming languages, variables work like containers to hold numbers, phrases, or other important stuff used in several places in your code.

WHAT DOES VARIABLE ACTUALLY MEAN?

Variable in simplest terms means “Something that Keep’s Changing”. In a shorter version of examples:

see, as when we are driving a car, the speed keeps changing at every second and we hardly stay at an ideal speed for a longer period of time (until we are on Motorway in Pakistan 😆). Ask yourself the Question, You are traveling from Abbottabad to Islamabad, can you keep the same speed throughout the route? , if the answer is No, then it’s a variable!

Another good example is: The Prime Minister of Pakistan is currently Imran Khan. But a few years ago, it was Nawaz Sharif. Later, it could be someone else entirely!

Ask yourself questions about other things and comment which variable have you found out?

WHAT IS A VALUE/DATA AND IDENTITY?

The quantities, characters, or symbols on which operations are performed by a computer!

Probably, it’s getting above your head, Ain’t it?. Value as the word mean’s something that adds’s value to something. Let’s understand it in the simplest terms again. Here it goes:

The tea inside a cup is the Value for the Cup. | CUP is the identity.

The books inside a bag are the Value for the Bag. | BAG is the Identity!

WHAT IS A VARIABLE IN PYTHON?

1*ttlYFOZ4ZAVf4b2IMroaUQ.png (576×427)

A variable is just a container that holds something inside. Variable in Programming generally is a collection of all of the above. We define an identity and assign a value to it. A variable is just a container that holds something inside such as:

CONCEPT 1: See the Pencil Holders in the above image (The black one). What’s it Identity? → Pencil Holder but currently, it’s empty which means that it does not hold value but it has free space to hold Pencils, cubes etc (In programming terms, it’s called void/None/Null)

1*hLYbEEm6bLGkVDQbl2lt-A.png (300×300)
A variable (pencil holder) that has value 1 (one cube).

CONCEPT 2: Now we have added a cube to the Pencil holder which means that it now has something and is no more Empty. In Programming terms, the Variable has some value now.

What’s the Value? The Number of Cubes perhaps!

1*zGC40PZAS_3-HJAkMj1rJg.png (300×320)

CONCEPT 3: We give one of our own identity to the Pencil Holder to uniquely distinguish it between other Pencil Holders. The name can be anything.

CONCEPT 4: See the value in the Pencil Holder has increased from one. You can actually change the value to whatever you wish!

CONCEPT 5: The Cubes are inside the Pencil Box, inside the boundary of Pencil Holder, that’s called scope!

Let’s get a Summarized Version of the Concepts:

CONCEPT 1: A variable is just a container that holds something inside.

CONCEPT 2: A value is what a variable contains.

CONCEPT 3: Variables can have names.

CONCEPT 4: The value of a variable can be changed. Also, The name of a variable can be changed.

CONCEPT 5: Every variable has a Scope.

--

--