Run this notebook

Use Livebook to open this notebook and explore new ideas.

It is easy to get started, on your machine or the cloud.

Click below to open and run it in your Livebook at .

(or change your Livebook location)

# Hello World! Here's how you write a `Hello World` script in Elixir. ```elixir IO.inspect("Hello World!") ``` <!-- livebook:{"output":true} --> ``` "Hello World!" ``` ## Variable Assignment Assigning a value to a variable is super simple in Elixir. You just write `my_var =` and whatever is on the right side of the `=` sign gets assigned to the variable. Here is how to assign all the different basic types to variables: ```elixir name = "Peter" # String age = 32 # Integer age_hex = 0x20 # Integer in Hex notation height = 190.47 # Float height_sci = 1.9047e2 # Float in scientific notation adult? = true # Boolean status = :active # Atom address = nil # The 'None/null/Nil' value IO.inspect([name, age, age_hex, height, height_sci, adult?, status, address]) ``` <!-- livebook:{"output":true} --> ``` ["Peter", 32, 32, 190.47, 190.47, true, :active, nil] ``` Variables are **immutable** but can be reassigned. This means that the memory holding the old value will not be overwritten; instead, new memory is allocated to hold the new value while the old value remains until garbage collected. Even if you modify a variable, it is not updated in place but copied to a new chunk of memory. This might seem wasteful, but it prevents different processes from modifying the same variable. ```elixir age = 32 age = 21 IO.inspect(age) ``` <!-- livebook:{"output":true} --> ``` 21 ``` You can ignore assignments by prefixing the variable name with an underscore: ```elixir _ = 30 _result = 30 + 32 ``` ## String Interpolation and Concatenation You can interpolate and concatenate strings like this: ```elixir # Interpolate a string with values name = "Peter" age = 32 IO.inspect("My name is #{name} and I am #{age} years old") # Concatenate two strings IO.inspect("But my real name is " <> "Batman 🦇") ``` <!-- livebook:{"output":true} --> ``` "My name is Peter and I am 32 years old" "But my real name is Batman 🦇" ```
See source

Have you already installed Livebook?

If you already installed Livebook, you can configure the default Livebook location where you want to open notebooks.
Livebook up Checking status We can't reach this Livebook (but we saved your preference anyway)
Run notebook

Not yet? Install Livebook in just a minute

Livebook is open source, free, and ready to run anywhere.

Run on your machine

with Livebook Desktop

Run in the cloud

on select platforms

To run on Linux, Docker, embedded devices, or Elixir’s Mix, check our README.

PLATINUM SPONSORS
SPONSORS
Code navigation with go to definition of modules and functions Read More ×