Null Values in Julia and Python

In Julia we usually use nothing of type Nothing to represent null. In Python one uses None of type NoneType. However nothing in Julia is just a convention, it has no special meaning in Julia, other than libraries by convention returning nothing objects when nothing is found.

I could instantiate a Nothing object like any other type:

julia> a = Nothing()

julia> typeof(a)
Nothing

In Python NoneType does not seem like a normal type.

python> NoneType()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'NoneType' is not defined

Meaning you cannot instantiate it, while you can e.g. instantiate other types this way:

python> int()
0
python> bool()
False

The explanation for this behavior seems to be that you cannot instantiate NoneType because it is a singleton. However Nothing in Julia is a singleton as well, but its constructor is defined as:

Nothing() = nothing

Next we’ll look at type annotation in Julia and type hints in Python.

Written by

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store