# Newbie Syntax Help: Colon in Index Syntax ---\> sepal\_length\_column = iris\[:Sepal\_Length\]

**URL:** https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918
**Category:** General Usage
**Created:** [June 25, 2018, 2:42am UTC](https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918 "2018-06-25T02:42:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Eli\_Hughes](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@Eli\_Hughes](https://discourse.julialang.org/u/Eli_Hughes)
#### Post date: [June 25, 2018, 2:42am UTC](https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918/1 "2018-06-25T02:42:22Z")

</div>

Hello:

I need some help to a doc page for a particular syntax (keep in mind I am a c programmer…) I have seen code that looks like this:

sepal\_length\_column = iris[:Sepal\_Length]

In the case above, it was an example from the dataframes module. What is the syntax in the square brackets? It is being used like array interation but with a string. I have not seen this type of syntax in other languages. I have also seen in in the PyPlot library. here is an example:

ax[:spines][“top”]:set\_color # Remove the top axis boundary

In this case :spines looks like it is some sort of binding to a class member in matplotlib.

A pointer to what this syntax is called would be helpful.

Thanks.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [June 25, 2018, 2:57am UTC](https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918/2 "2018-06-25T02:57:19Z")

</div>

the square bracket syntax `[]` is just shorthand for the function `getindex` defined in Base.

Think of a DataFrame as an array of arrays, each one for a column. Then they define new methods for the function `getindex` to have the desired behavior. You can do this too.

```julia
struct A 
     x::Vector
end

import Base.getindex

function getindex(a::A, n)
     getindex(A.x, n)
end

x = ["here", "there", "everywhere"]

a = A(x)

a[1]

> "here"

```

---

<div class="post-metadata">

### Author: ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)
#### Post date: [June 25, 2018, 4:56am UTC](https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918/3 "2018-06-25T04:56:08Z")

</div>

prefixing text with a colon gives a `Symbol`, e.g. `:foo`, `:bar`. The `Dataframes` package allows a `DataFrame` to be indexed with a `Symbol` to refer to the column with that name.

The `PyCall` package allows python libraries to be called from Julia code, but translates a `obj.field` in Python into `obj[:field]` in Julia. see the [usage section of the docs](https://github.com/JuliaPy/PyCall.jl#usage) for details.

also - please surround quoted code with back-ticks so it gets nice syntax highlighting and is displayed in a fixed-width font. Single backticks are for in-line code `like this`, and triple quotes are used for longer code:

```julia
like this

```

---

<div class="post-metadata">

### Author: ![Eli\_Hughes](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@Eli\_Hughes](https://discourse.julialang.org/u/Eli_Hughes)
#### Post date: [July 1, 2018, 6:09pm UTC](https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918/4 "2018-07-01T18:09:55Z")

</div>

Thanks for the replies. Very Helpful!

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [July 1, 2018, 8:16pm UTC](https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918/5 "2018-07-01T20:16:43Z")

</div>

FWIW on Julia 0.7 one can also write `iris.Sepal_Length` instead.

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [July 1, 2018, 8:17pm UTC](https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918/6 "2018-07-01T20:17:08Z")

</div>

FWIW on Julia 0.7 one can also write `iris.Sepal_Length` instead, which calls the `getproperty`/`setproperty!` functions.

---

<div class="post-metadata">

### Author: ![swissr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swissr/32/208_2.png) [@swissr](https://discourse.julialang.org/u/swissr)
#### Post date: [July 2, 2018, 8:45am UTC](https://discourse.julialang.org/t/newbie-syntax-help-colon-in-index-syntax-sepal-length-column-iris-sepal-length/11918/7 "2018-07-02T08:45:28Z")

</div>

There is a very good explanation about what is a _symbol_ on stackoverflow by Stefan Karpinski. Link: [What is a "symbol" in Julia? - Stack Overflow](https://stackoverflow.com/questions/23480722/what-is-a-symbol-in-julia).
