June 14, 2026•5 min read

Variables and Data Types in Programming

A variable is the main character of a program, and every language has one. The type is what decides which data fits inside.

Read in Indonesian

A variable is the main character of a program. Whatever programming language you pick, you will run into the variable concept. You could say a variable is the heart of programming, because it is the thing responsible for storing and manipulating data.

Key takeaways

  • A variable is a named container for data, so you can use that data again when you need it.
  • Every piece of data has a shape of its own (data type), and that shape decides which operations are allowed on it.
  • The standard types you meet most often are integer, float, string, boolean, and array.

What Is a Variable?

Let's peek at Wikipedia first, to get the formal definition.

… a variable is a storage location paired with a symbolic name that holds some known or unknown quantity, information, or value wikipedia

There it is, the formal definition. A bit of a mouthful, right? So to make it easy, picture a variable as a kind of container for data that you can use again later in the program. In the real world, a variable is like a water bottle, and the data is the water inside. You can fill the bottle and drink from it whenever you like, and you are even free to add syrup or sugar to change the taste. The same goes for a variable: you can put data in, take it out, or swap the contents for other data. On top of that, a variable gives you a way to manipulate data according to the logic you want.

What You Can Do with a Variable

1. Declaring a variable

The first step is declaration, the process of "creating" a variable. At this stage you tell the computer that a new "container" exists and is ready to hold data. Every language declares variables differently, but one thing is certain: a variable must have a clear name. There are naming rules too, and each language has its own style you need to follow. Because of that, the most important thing is that a variable name means something and reads easily, so it does not confuse anyone later. If you want to store a person's age, name the variable umur, and do not make it up as you go.

2. Assigning a value (Assignment)

Once the container exists, it is time to put something inside. In programming, filling a variable with a value is usually called assignment. You normally use the equals sign (=) for this. The variable name goes on the left, and the value you want to store goes on the right. That rule looks a lot like the math you did in school, doesn't it?

For example:

PYTHON
nama = "Inva"
PI = 3.14
r = 10

One thing to remember: not every language uses =. Some use :=, like Pascal or Go, so check the documentation for your language.

3. Reading the value

Now that the container is filled, you can take the data back out. To read a value inside a variable, you only need to call its name. That is easy enough, right? If you want to read the variable nama and print it to the screen:

PYTHON
nama = "Inva"
print(nama)

When that code runs, the output looks like this:

TEXT
Inva

4. Operating on data

Last, and no less important, you can operate on the data. That means you can apply special treatment to whatever lives inside the variable. If a variable holds a number, you are free to add, subtract, or run any other arithmetic operation. If it holds a string (text) such as a full name, you can split it into first and last name, or simply change the letters to uppercase.

But remember, a variable is quite picky! It does not want to be operated on with data of a different kind. Imagine adding a number to text, something like 2 + 'semangka'. What would the result even be? You would be confused, and so would the computer. This strange thing happens because the two are not the same kind, meaning they have different data types: one is a number (int) and the other is text (string). So what is a data type?

What Is a Data Type?

Once again, let's ask Wikipedia for the official definition.

… a data type is a classification of data that tells a compiler or interpreter how the programmer intends to use the data wikipedia

If a variable is the container, then the data type is the shape and material of that container. Logically, every container is designed from a different material depending on what goes inside. You store water in a bottle and clothes in a suitcase. You would not swap them and put water in a suitcase, would you? 😅 With a data type, you automatically tell the computer that a given variable can only hold a specific kind of data.

The Kinds of Data Types

Programming languages generally recognize two main groups of data types: standard types and derived types. Standard types come built into the language itself. Some of the ones you will use most:

  • integer: For whole numbers (examples: 1, 2, -90).
  • float: For decimal numbers (examples: 2.5, 3.14, -2.71).
  • char: For a single character only (examples: 'a', '$', '?').
  • string: For letters or long text (examples: "a", "ikan", "Halo kawan").
  • byte: For raw data like images or files.
  • boolean: For logical values, only true and false.

Beyond that, some languages have other variants depending on their spec, for example:

  • long: Like integer, but with a much bigger capacity.
  • double: Similar to float, but with more digits after the decimal point (high precision).
  • uint or unsigned integer: Whole numbers reserved for positive values only.
  • array or list: For many values in one variable, as long as the types match.
  • pointer: An advance type that stores the memory address of another variable.

Besides the built-in types, there are also derived types. As the name suggests, the programmer builds these for a more specific need. Usually a derived type combines several different standard types.

Conclusion

The point is that variables and data types are fundamental to programming. A variable makes it easy to store and manipulate data inside a program, while the data type decides which kinds of data can go in. Combining the two concepts keeps your code efficient and keeps it from breaking into error. So, do you see the difference between variable and data type now? If something is still unclear, let's talk about it in the comments! Happy coding 👋

Get better at shipping code.

Join the other developers getting tech updates, tips, and relaxed tutorials in their inbox every week.

Stay in the loop

Tech updates, coding tips, and relaxed insights straight to your inbox every week.

No spam. Unsubscribe anytime.

Read next

See all

For developers who learn by struggling

© 2026 Inva.dev.