Basic Datatypes in Programming

mbvissers.eth
CodeX
Published in
4 min readMar 5, 2022

--

Strings, Integers, Booleans, and Arrays

Photo by AltumCode on Unsplash

If you’re fairly new to programming, all the different data types might seem very daunting. There are a lot of terms you might not have heard before or don’t know how they relate to programming.

In this article, I will try and explain the basic data types you will encounter in your programming studies and explain them well enough for you to understand, but that it is still easy to follow. Enjoy.

Strings

Strings are one of the most basic types in programming. You can think of them as a list of characters. Or more easily said, they are just plain text.

They are assigned to variables by using quotation marks to indicate it is a string. At least in most programming languages.

your_variable := "your string"

You will often see strings being used in programming courses by writing “Hello World” which you can say, is tradition for your first application.

Strings can also be concatenated. Which means you can add two strings together into a single string. This is often done with the plus sign.

string1 := "Hello "
string2 := "World"
string3 := string1 + string2
print(string3) // Prints "Hello World"

Some languages allow more complex operations on strings, but we will not get into them. Strings are not very complex at this level, and we don’t need to get more into it at the moment. Let’s get on to the next data type.

Integers

Integers or ints are numbers. Very simply said at least. They often range from roughly minus 2.1b to positive 2.1b. This is because of how they are stored. Some languages might have other data types like long s for larger numbers. Pretty often, this won’t matter though.

You can always perform regular mathematical operations on them by default. They are also often written without any quotations or other marks.

num1 := 6
num2 := 12
num3 := num1 + num2 // = 18
num4 := num2 - num1 // = 6
num5 := num2 / num1 // = 2
num6 := num1 * num2 // = 72

The thing about integers is that they cannot have a decimal point in most statically typed languages like C# or Java. They have float s instead.

Floats

The name float comes from floating-point maths in which a number does contain a decimal point. How they’re declared varies from language to language so I will not get into it very deeply. Most commonly you have to use the float keyword before assigning the variable, and suffix the number with an f . Like float your_var := 3.14f .

Booleans

Booleans might seem like the most basic data type, it can just be true or false . But getting into actual boolean logic and math can become difficult pretty fast. But we do not get into that.

They are declared with both the true or false keywords in most languages. Some statically typed languages need bool before it as well.

my_var1 := true
my_var2 := false

The complexity comes from conditional statements that require boolean values to choose a path. Most commonly known as if-statements.

my_var := true
if my_var == true:
do_something()
else:
do_something_else()

These can be very simple, or they can feature multiple boolean values that need to be the same (AND) or only a single value needs to be true (OR).

With these, you can create complex boolean logic that you might encounter later on when writing programs.

Arrays

Arrays, also known as lists, differ greatly depending on the language you use. But they almost always have some similarities. They can sometimes contain a single data type, or they can be dynamic and contain every type you want.

my_list := [1, 3, 5, 7]
my_other_list := ["a", "b", "c"]

They are often written with brackets [] with the values between them separated by commas. You can access each value whenever you want by accessing the list with the index of the value you want to access.

my_list := ["a", "b", "c"]
my_val := my_list[1] // "b"

Lists are almost always 0-indexed, which means that the first item of the list will be at number 0.

Arrays can be difficult to fully grasp for some developers, but with enough practice, you will master these in no time.

Conclusion

Programming can be really difficult at first, but just by taking it slowly and learning each tiny part of development, you can become a great programmer.

Thank you so much for reading and have an excellent day.

Consider supporting me by getting a Medium membership. It helps me out a lot, it won’t cost you anything extra, and you can read as many Medium articles as you like!

Follow me on Twitter and gm.xyz to keep up with my projects.

Check out the Kangaroo Mob NFT project.

Check out Pixel Pizzas on Polygon.

--

--

mbvissers.eth
CodeX

I occasionally write about programming. Follow me on Twitter @0xmbvissers