# Why it has "\_," in front of some variables

**URL:** <https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 7, 2023, 5:15pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685 "2023-03-07T17:15:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jianqixi](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jianqixi](https://discourse.julialang.org/u/jianqixi)\
**Post date:** [March 7, 2023, 5:15pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/1 "2023-03-07T17:15:01Z")

</div>

Hi I am a very beginner of the julia, when taking the online class, I found some examples they use “_, vars" in the code. I am wondering what’s the meaning of "_,” and why use it? Thanks

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [March 7, 2023, 5:20pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/2 "2023-03-07T17:20:10Z")

</div>

I think an example would be helpful.

---

<div class="post-metadata">

**Author:** ![jianqixi](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jianqixi](https://discourse.julialang.org/u/jianqixi)\
**Post date:** [March 7, 2023, 5:28pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/3 "2023-03-07T17:28:23Z")

</div>

Thank you for your reply. Here is one example:

function findclosest(data, point)  
\_, index = findmin(abs.(data .- point))  
return data[index]  
end  
data = rand(5000)  
findclosest(data, 0.5)

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 7, 2023, 5:30pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/4 "2023-03-07T17:30:23Z")

</div>

The `_` is not actually in front of a variable in this case, it is a symbol used to destructure the tuple without storing its first element in a named variable. The function [`findmin`](https://docs.julialang.org/en/v1/base/collections/#Base.findmin) returns a tuple composed of a value and an index, but here we don’t care about the value so this is our way of telling Julia to not do anything with it.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 7, 2023, 5:31pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/5 "2023-03-07T17:31:05Z")

</div>

In other settings, putting `_` in front of a variable or function may also indicate that it is reserved for internal use in a package, and not part of the public API (in other words, steer clear of it)

---

<div class="post-metadata">

**Author:** ![jianqixi](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jianqixi](https://discourse.julialang.org/u/jianqixi)\
**Post date:** [March 7, 2023, 5:34pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/6 "2023-03-07T17:34:09Z")

</div>

I see, now it makes clear to me. BTW, is it a general rule that if we used “\_,” then it means we are trying to ignore the first output of the function? Thanks

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [March 7, 2023, 5:46pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/7 "2023-03-07T17:46:39Z")

</div>

Yes. A bare underscore (or a number of underscores) is a valid variable name only on the left hand side of an assignment, so it’s a clear signal that you do not intend to use that variable - you can’t. Of course you could just as well use an actual variable name and just not use it, at no extra cost, but then you lose the signal.

Another common place you will see this is `for _ = 1:50` which means “repeat loop 50 times, I don’t need a counter”.

---

<div class="post-metadata">

**Author:** ![jianqixi](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jianqixi](https://discourse.julialang.org/u/jianqixi)\
**Post date:** [March 7, 2023, 5:58pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/8 "2023-03-07T17:58:01Z")

</div>

Thank you for your clarification.

---

<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:** [March 7, 2023, 8:15pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/9 "2023-03-07T20:15:33Z")

</div>

> [@gustaphe](#):
>
> Of course you could just as well use an actual variable name and just not use it, at no extra cost, but then you lose the signal.

I’m curious: it is just ahestetics, or the compiler may take some advantage of that information, relative to using a random variable name? Is the underscore special in some sense for the compiler?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 7, 2023, 8:22pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/10 "2023-03-07T20:22:35Z")

</div>

> [@lmiq](#):
>
> Is the underscore special in some sense for the compiler?

It is special cased in the parser (in lowering):

```julia
In [1]: 1 + _
ERROR: syntax: all-underscore identifier used as rvalue

```

But there aren’t really any optimizations that can be made from this.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [March 7, 2023, 9:18pm UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/11 "2023-03-07T21:18:34Z")

</div>

In a closed scope I would imagine there’s no difference after compilation, the compiler will know it doesn’t need to store the variable, whether it has a name or no. In global scope maybe there is a performance difference. I don’t know.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [March 8, 2023, 4:08am UTC](https://discourse.julialang.org/t/why-it-has-in-front-of-some-variables/95685/12 "2023-03-08T04:08:02Z")

</div>

> [@lmiq](#):
>
> I’m curious: it is just ahestetics, or the compiler may take some advantage of that information, relative to using a random variable name? Is the underscore special in some sense for the compiler?

This discussion is relevant: [Dummy variable \_ · Issue #9343 · JuliaLang/julia (github.com)](https://github.com/JuliaLang/julia/issues/9343)
