# Functions and additional exclamation mark '!'

**URL:** <https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198>\
**Category:** General Usage\
**Created:** [August 14, 2024, 7:41pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198 "2024-08-14T19:41:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![EatMyShorts](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@EatMyShorts](https://discourse.julialang.org/u/EatMyShorts)\
**Post date:** [August 14, 2024, 7:41pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/1 "2024-08-14T19:41:18Z")

</div>

Hello …

While I was reading through some tutorials, I noticed a function call with an additional “!”. For example here (and also for my solved problem): [MTH229 with Julia - 3&nbsp; Graphing functions with Julia](http://mth229.github.io/graphing.html)

“Graphs can be layered by using the `plot!` function (with an exclamation point indicating a current graph is begin modified).”

That’s actually clear to me.

But I have seen another function calls with “!”, for example in our numerical framework code. Can someone explain to me (maybe with an easy example) what the exact idea of ​​the “!” is?

Kind regards

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [August 14, 2024, 7:44pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/2 "2024-08-14T19:44:28Z")

</div>

`!` is a naming convention used for functions that mutate an argument. For example `rand!(v)` fills `v` with random numbers.

---

<div class="post-metadata">

**Author:** ![EatMyShorts](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@EatMyShorts](https://discourse.julialang.org/u/EatMyShorts)\
**Post date:** [August 14, 2024, 7:46pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/3 "2024-08-14T19:46:44Z")

</div>

And what happens when I just use rand(v) without “!”?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 14, 2024, 7:50pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/4 "2024-08-14T19:50:39Z")

</div>

It’s a different function entirely that can do something totally different. In the case of `rand(v)` where `v` isa vector, it randomly picks an element from it.

A more conventional pair is `sort!` vs `sort` — the former sorts a vector in-place, while the latter returns a brand new vector with the same elements in sorted order. If you’re familiar with Python, it’s the difference between `v.sort()` and `sorted(v)`.

The case with `plot!` vs `plot` is quite similar — the former _adds_ an element to an existing plot, whereas the latter creates a brand new plot from scratch.

But the point is that these are all just different functions with different names. The convention about what the `!` means is just that — a convention. You can sometimes look at a pair of functions like `embiggen` and `embiggen!` and have a guess at what they would each do (if you know what it means to embiggen something, that is), but the real answer is to check the docs for each one independently.

---

<div class="post-metadata">

**Author:** ![EatMyShorts](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@EatMyShorts](https://discourse.julialang.org/u/EatMyShorts)\
**Post date:** [August 14, 2024, 7:59pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/5 "2024-08-14T19:59:05Z")

</div>

I noticed it today with plot vs plot!: I wanted to plot the datas into a chart for each loop run.  
Just plot: I just got a white chart with no data set  
plot!, with “!”: I got a chart with all data sets

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [August 14, 2024, 7:59pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/6 "2024-08-14T19:59:17Z")

</div>

[https://docs.julialang.org/en/v1/manual/style-guide/](https://docs.julialang.org/en/v1/manual/style-guide/)

> Append `!` to names of functions that modify their arguments

---

<div class="post-metadata">

**Author:** ![EatMyShorts](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@EatMyShorts](https://discourse.julialang.org/u/EatMyShorts)\
**Post date:** [August 14, 2024, 8:07pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/7 "2024-08-14T20:07:27Z")

</div>

Could the functions simply be named differently (without any “!”)?  
If plot and plot! are different functions …  
For example, could you have simply called plot! as “forest” (which makes no sense!)?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 14, 2024, 8:16pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/8 "2024-08-14T20:16:50Z")

</div>

Yes, exactly! They’re just different functions with different names. In fact, you can even choose the names for these functions when you load Plots.jl:

```julia
julia> using Plots: plot as beginulate, plot! as blurst!!eleventy1!!

julia> beginulate(1:10, rand(10))

julia> blurst!!eleventy1!!(1:10, randn(10))

```

![image](https://global.discourse-cdn.com/julialang/original/3X/b/0/b0836e53d36192b668b2f461275b45932f239e2c.png)

---

<div class="post-metadata">

**Author:** ![EatMyShorts](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@EatMyShorts](https://discourse.julialang.org/u/EatMyShorts)\
**Post date:** [August 14, 2024, 8:18pm UTC](https://discourse.julialang.org/t/functions-and-additional-exclamation-mark/118198/9 "2024-08-14T20:18:40Z")

</div>

Great! Thank you very much ;)!
