None value in Julia

前端 未结 1 557
灰色年华
灰色年华 2021-02-06 21:35

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

1条回答
  •  后悔当初
    2021-02-06 22:33

    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 Void after the return type of C functions with nothing interesting to return.

    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:

    • https://docs.julialang.org/en/v1/manual/faq/#faq-nothing-1

    0 讨论(0)
提交回复
热议问题