What is the Julia equivalent of the None
value in Python? (As shown here in built-in constants.)

- 32,404
- 10
- 86
- 111

- 1,962
- 3
- 20
- 44
-
2http://docs.julialang.org/en/release-0.4/manual/types/#nullable-types-representing-missing-values – DeepSpace Jun 10 '16 at 15:09
-
3@SimonFraser: the Python `None` value is quite different from `null` in C or Java. Python also does not have a C-like `null`. – StefanKarpinski Jun 10 '16 at 15:49
1 Answers
The Julia equivalent of None
is the constant nothing
: a value that is returned by expressions and functions which don't have anything interesting to return. In both languages, this value is not printed at an interactive prompt when an expression evaluates to it, but is otherwise just a normal value. There's nothing magical about it other than the printing behavior and the fact that people agree by convention that it is the value one returns when there is nothing interesting to return. The type of nothing
is called Nothing
(and has Cvoid
as an alias for use with C functions).
Julia's type system can also express the concept that an expression cannot produce any value – e.g. if it throws an error or is part of a basic block that cannot execute (dead code). The type of an expression that can never produce a value is the empty union type, Union{}
: a union of zero types, of which no values are instances. This is distinct from the type of nothing
– since nothing
is a normal (but uninteresting) value, so it cannot be an instance of Union{}
.
See Also:

- 32,404
- 10
- 86
- 111
-
14Note to readers: as of Julia 0.7, [the type of `nothing` is `Nothing`](https://docs.julialang.org/en/latest/base/constants/#Core.nothing), i.e. the type Void has been renamed to `Nothing` (or re-renamed, since that was its original name). There's also an alias `Cvoid` to refer to `Nothing`, which can be handy when doing C-interop. (https://github.com/JuliaLang/julia/issues/25082) – Sundar R Apr 01 '18 at 19:04