Data Types
Get familiar with different built-in data types of Elixir.
Elixir is a dynamic programming language. So, we don’t declare the type of each variable. It depends on the value it holds at each moment. In this lesson, we’ll learn more about Elixir’s basic data types: integers, floats, booleans, atoms, strings, lists, and tuples. Below is the description of available data types in Elixir.
Built-in types
Elixir’s built-in types are as follows:
- Value types:
- Arbitrary-sized integers
- Floating-point numbers
- Atoms
- Ranges
- Regular expressions
- System types:
- PIDs and ports
- References
- Collection types:
- Tuples
- Lists
- Maps
- Binaries
Functions are a type too. But they have their own chapter.
Value types
The value types in Elixir represent numbers, names, ranges, and regular expressions.
Integers
Integer literals can be written as decimal (1234
), hexadecimal (0xcafe
), octal (0o765
), and binary (0b1010
). Decimal numbers may contain underscores (_
). These are often used to separate groups of three digits when writing large numbers, so one million could be written 1_000_000
(or perhaps 100_0000
in China and Japan). ...