# Is there a builtin type in julia equivalent to python \`None\`?

**URL:** https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560
**Category:** General Usage
**Tags:** question
**Created:** [July 3, 2024, 4:39am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560 "2024-07-03T04:39:09Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![VinodV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinodv/32/32733_2.png) [@VinodV](https://discourse.julialang.org/u/VinodV)
#### Post date: [July 3, 2024, 4:39am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/1 "2024-07-03T04:39:09Z")

</div>

Is there a builtin type in julia equivalent to python `None` in Julia?

```julia
[0, 1, false, 2, "", 3, 'a', 's', 34,[],missing] |> filter(func) 

# [1, 2, 3, 'a', 's', 34]

```

What `func` could be. Why empty character `''` is disallowed in Julia?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 3, 2024, 4:53am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/2 "2024-07-03T04:53:35Z")

</div>

`nothing`

---

<div class="post-metadata">

### Author: ![VinodV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinodv/32/32733_2.png) [@VinodV](https://discourse.julialang.org/u/VinodV)
#### Post date: [July 3, 2024, 4:56am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/3 "2024-07-03T04:56:30Z")

</div>

> [@VinodV](#):
>
> [0, 1, false, 2, “”, 3, ‘a’, ‘s’, 34,,missing] |\> filter(func)

```julia
julia> [0, 1, false, 2, "", 3, 'a', 's', 34,[],missing] |> filter(isnothing)

Any[]

```

```julia
julia> [0, 1, false, 2, "", 3, 'a', 's', 34,[],missing] |> filter(!isnothing)
11-element Vector{Any}:                                                      
     0                                                                       
     1                                                                       
 false                                                                       
     2                                                                       
      ""                                                                     
     3                                                                       
      'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)             
      's': ASCII/Unicode U+0073 (category Ll: Letter, lowercase)             
    34                                                                       
      Any[]                                                                  
      missing                                                                

```

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 3, 2024, 5:04am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/4 "2024-07-03T05:04:39Z")

</div>

I don’t know what pattern you’re looking for, but maybe:

```julia
julia> is_whatever(x::Number) = iszero(x)

julia> is_whatever(x::AbstractString) = isempty(x)

julia> is_whatever(x::AbstractArray) = isempty(x)

julia> is_whatever(x::Missing) = true

julia> is_whatever(x::Nothing) = true

julia> is_whatever(x::Bool) = !x

julia> is_whatever(x::Char) = false

julia> [0, 1, false, 2, "", 3, 'a', 's', 34,[],missing] |> filter(!is_whatever)
6-element Vector{Any}:
  1
  2
  3
   'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
   's': ASCII/Unicode U+0073 (category Ll: Letter, lowercase)
 34

```

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [July 3, 2024, 5:04am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/5 "2024-07-03T05:04:58Z")

</div>

> [@VinodV](#):
>
> Why empty character `''` is disallowed in Julia?

There is no such thing as an empty character. There is an empty string which is a string with no characters.

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [July 3, 2024, 5:10am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/6 "2024-07-03T05:10:57Z")

</div>

The example code you gave uses the Python concept of “truthy”/“falsy” values, in which `bool(x)` returns `false` for empty containers and `None` and `0`. Julia doesn’t have this concept: instead you can explicitly check the property you want, such as `isempty` or `iszero`.

---

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [July 3, 2024, 5:56am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/7 "2024-07-03T05:56:14Z")

</div>

Related discussion:

> [@On the arbitrariness of truth(iness)](https://discourse.julialang.org/t/on-the-arbitrariness-of-truth-iness/81381):
>
> Occasionally someone will be annoyed that Julia requires an actual true or false value in conditionals, whereas many dynamic languages (including Lisps) allow arbitrary values in conditions and have rules about what count as “truthy” or “falsey” in that context. Many static languages even allow a degree of this: C doesn’t have a boolean type and instead uses non-zero integer values to indicate truth and zero values to indicate false. Julia could easily do something along these lines by having a B…

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [July 3, 2024, 7:21pm UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/8 "2024-07-03T19:21:39Z")

</div>

The high-level point that applies here is that I have no idea what you want those filter operations to do. Which elements did you want to keep? Why? I’m also a little confused what the example has to do with the Python `None` type…

---

<div class="post-metadata">

### Author: ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)
#### Post date: [July 3, 2024, 8:16pm UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/9 "2024-07-03T20:16:24Z")

</div>

An example might help, too: A string is roughly analogous to an array of integers. It makes sense to have an empty array of integers. For example, if it is mutable, remove all the elements. But it doesn’t make sense to talk about an empty integer. Both strings and arrays are variable length containers, and that length can be zero

(This really applies to utf8 strings, but if you prefer, consider just ascii strings.)

It makes sense that the OP might be confused about empty characters, but not about empty integers. This is clearly an artifact of how characters are constructed, with two single quotes, eg `'c'`. You might think since it looks a lot like a string, maybe it shares a lot of properties with a string.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [July 3, 2024, 8:54pm UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/10 "2024-07-03T20:54:16Z")

</div>

In addition to the previous answers, note that for most functions:

- `missing` silently propagate to `missing` (e.g. `sum([1,2, missing])` evaluates to `missing`)
- `nothing` results in an error (e.g. `sum([1,2, nothing])` results in an error when evaluated)

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [July 3, 2024, 11:23pm UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/11 "2024-07-03T23:23:28Z")

</div>

> [@jlapeyre](#):
>
> This is clearly an artifact of how characters are constructed, with two single quotes, eg `'c'`.

In Python (and Matlab, and perhaps others) strings can be created with single quotes, as well as with double quotes, unlike in Julia, where characters and strings are distinct. In Python or Matlab, `''` is a valid value.

---

<div class="post-metadata">

### Author: ![VinodV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinodv/32/32733_2.png) [@VinodV](https://discourse.julialang.org/u/VinodV)
#### Post date: [July 4, 2024, 1:09am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/12 "2024-07-04T01:09:41Z")

</div>

I want to extract valid data points from a list, since null-like/empty-like entries contains no information.

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [July 4, 2024, 1:36am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/13 "2024-07-04T01:36:13Z")

</div>

> [@VinodV](#):
>
> What `func` could be.

```julia-repl
julia> func(val) = typeof(val) in (Int, Char) 
func (generic function with 1 method)

julia> [0, 1, false, 2, "", 3, 'a', 's', 34,[],missing] |> filter(func)
7-element Vector{Any}:
  0
  1
  2
  3
   'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
   's': ASCII/Unicode U+0073 (category Ll: Letter, lowercase)
 34

```

---

<div class="post-metadata">

### Author: ![alfaromartino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alfaromartino/32/52986_2.png) [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)
#### Post date: [July 4, 2024, 4:05am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/14 "2024-07-04T04:05:10Z")

</div>

I think if you define clearly what empty means, we could help. For example, I get a grasp of what you want, but then you also consider `false` as an empty value.

Following @lmiq, you could try something more specific like this

```julia
func2(val) = (val isa Union{Number, String}) && !isempty(val)
[0, 1, false, 2, "hello", 'a', "", nothing, [],missing] |> filter(func2)

```

which eliminates what you could consider “empty” (in the sense of not providing concrete information?)

```julia
5-element Vector{Any}:
     0
     1
 false
     2
      "hello"

```

but, again, the downside of this is that you need to specify the objects you want first, before indicating that you don’t want empty values. That’s why I used `String` instead of `Char`, but you should also add `Char`, `AbstractArray`, etc.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 4, 2024, 5:08am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/15 "2024-07-04T05:08:38Z")

</div>

> [@lmiq](#):
>
> ` 0`

this is “false” according to OP

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [July 4, 2024, 7:07am UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/16 "2024-07-04T07:07:25Z")

</div>

> [@VinodV](#):
>
> since null-like/empty-like entries contains no information.

But `0` or `false` _definitely_ contain information! Otherwise, you could compress any binary sequence (like eg. a file) by removing the zeros and keeping only the ones.

---

<div class="post-metadata">

### Author: ![gmcardle](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@gmcardle](https://discourse.julialang.org/u/gmcardle)
#### Post date: [July 9, 2024, 12:54pm UTC](https://discourse.julialang.org/t/is-there-a-builtin-type-in-julia-equivalent-to-python-none/116560/17 "2024-07-09T12:54:22Z")

</div>

Hey, that’s a brilliant idea for a new compression algorithm. You could then take it even further- since now it’s just a sequence of ones you can compress that to just the number of ones. Now we can compress any file of any size to just a single integer. It might be a bit lossy but surely the amazing compression factor is worth it!
