# Basic Data Types in Elixir Language

Introduction to basic data types in Elixir

Every programming language has data types. Data types is an attribute of data which tells the compiler or intepreter how the programmer intends to use the data according to Data types. Data can be stored in different ways depending on your intentions, for example, 20 could be used as an integer if i intend to use it in a loop counter but wont be appropriate if i need it for a more precise calculation. That example might be complex, so i will use something simpler, imagine you were chatting with your friend on Whatsapp, and he asks you how much you bought a book, you send a digit probably 95 to him, your intention at that point is to pass a message accross, the 95 is a number but with no intention to perform arithemetics with it, so its going to be stored as a 'string' by whatsapp, but also imagine on your whatsapp, you also have 95 unread messages on your whatsApp badge, when you open a message, it reduces to 94, the same value 95 but used differently based on the Programmer's intention.

Elixir has 7 basic data types namely: String, Integers, Float, Booleans, List, Tuple, Atoms. we take them at basic level

# Strings

Strings in elixir are in between double quotes, Strings are encoded in UTF-8, Strings are used to store texts, messages and many more. In IEx Interactive Elixir Session, Strings are outputted in green colour.

"I am a String"

To write a multiline string, place your content between triple double quotes


# Integers

In the Example above the 95 in your WhatsApp badge must be an integer, Integers are numbers without decimal point. They are used for basic arithemtics. In IEx, Integers are outputted in pale yellow colour Example:

iex(6)> 1 + 8

# Floats

A float is a number with a decimal, it has 64-bit double precision. In IEx, Floats are outputted as pale yellow

iex(7)> 1.12

# Boolean

A Boolean data type has one or two value. Either True or False. In IEx, Booleans are outputted in purple colour

iex(8)> true
iex(9)> false

# List

Think of lists in Elixir is Linked lists Linked Lists, but its just a container of values seperated by a comma within a square bracket. Again depending on your intentions, there are situation where lists is meant to be used and when you ought not to use it.

iex(1)> [1, 2, 3]
[1, 2, 3]

# Tuple

Tuple are basically Arrays in ELixirs, a container of values seperated by a comma within a curly brackets. I explain in our future articles when to use Lists and Tuple

iex(2)> {1, 2, 3}
{1, 2, 3}

# Atom

Finally, Atom is a weird data type but actually cool, an atom is a constant whose name is its value,

iex(5)> :ok

Yeah i know atoms are weird, but i cover atoms and its attribute in future articles. So today, you have learnt basic data types in Elixir, which is a rudiment in understanding elixir.

Thanks for reading..


Elixir school Tutorial Point

More from SoftNexus