Variables & Data

This is part of “An intro to Coding” series of posts, with content from the Enki app. If you stumbled upon this, you can start from the beginning.

In programming, we store data into variables.

Think of a variable as a box for information.

You might put books, linen, microwaves, and so on into a real-world box. In the programming world, all those physical objects would be replaced by data.

If you had a garage full of boxes and wanted to find the one containing books, you'd probably look for the one with the label "Books".

Programs are no different. In order to distinguish a variable from another, we label it with a name.

This helps us know what kind of data is contained in a particular variable.

Make sure to use descriptive names to help out anyone (including yourself at a later time) understand what information is contained in a particular variable.

💡 Think of a variable as a labeled box that holds some data.

To get us started, let's say that we have the text "Enki" as our data, and we want to store it in a variable named study_buddy:

💡 Unlike human names, variable names cannot hold spaces. Common naming conventions for multi-word variable names are to use snake case (study_buddy) or camelCase (studyBuddy).

In programming, putting data into a variable is usually done with the = sign:

💡 Don't worry about the quotation marks around "Enki" for now. We'll explain them in the insights coming up.

Putting data into a variable is called an assignment.

💡 Assignment is usually done right to left. Using "Enki" = study_buddy will not work.

Data Types

You can think of a data type as a category for information.

Just like how in most human languages a "house" and a "skyscraper" are both in the category of "building", in programming languages a 1 and 0xff¹ are both in the category of "number".

💡 Don't worry too much about the strange-looking 0xff. The core idea to focus on is that programs categorize data by type.

Most programming languages support at least some data types. The most common ones are:

  • number
  • text
  • boolean
  • list
  • dictionary

There are many more types, (and you can even build your own!) but you'll start learning them as you dive into a specific programming language.

Data types are very important! They decide what actions you can and cannot take for a particular value. One example is that you can't add the number 1 to the text "one".


[1] Computers commonly represent data using a hexadecimal system of 16 digits, unlike our everyday decimal system of 10 digits.

The 6 digits after 0-9 in hexadecimal are actually the letters a-f.

Using a system of 16 digits allows us to present more information with fewer characters.

Check out this article for more info

Chat with us to learn more

Continue reading

Our newsletter

Get the best curated articles

No spam!