# What is the colon in this code doing?

**URL:** <https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [November 20, 2022, 2:04pm UTC](https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628 "2022-11-20T14:04:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atlas5779](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@Atlas5779](https://forum.freecodecamp.org/u/Atlas5779)\
**Post date:** [November 20, 2022, 2:04pm UTC](https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628/1 "2022-11-20T14:04:30Z")

</div>

```auto
def print_board(self):
        for row in [self.board[i*3:(i+1) * 3] for i in range(3)]:
            print('| ' + ' | '.join(row) + ' |')

```

Can anyone explain this? It’s from FreeCodeCamps video tutorial. I have no idea what the colon dose in this part of the code [i\*3:(i+1) \* 3]

‘’’

---

<div class="post-metadata">

**Author:** ![anasL](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/anasl/32/243340_2.png) [@anasL](https://forum.freecodecamp.org/u/anasL)\
**Post date:** [November 20, 2022, 2:25pm UTC](https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628/2 "2022-11-20T14:25:11Z")

</div>

Basically selecting the items in the list ‘board’ that have indexes equal to the values in the range:

`[i*3,(i+1)*3[ <==> from i*3 to (but not including) (i+1)*3`

Also similar functionality to array.splice() in javascript.

---

<div class="post-metadata">

**Author:** ![Atlas5779](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@Atlas5779](https://forum.freecodecamp.org/u/Atlas5779)\
**Post date:** [November 25, 2022, 3:30pm UTC](https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628/3 "2022-11-25T15:30:39Z")

</div>

The use of the colon is the main thing that I do not understand here. When I look up Python colon, I get no answer. Does it work like an equal sign here? dose it end a line of code? Dose it just separate the two parts of Code? I do not know JavaScript.

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [November 25, 2022, 3:37pm UTC](https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628/4 "2022-11-25T15:37:03Z")

</div>

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [November 25, 2022, 3:41pm UTC](https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628/5 "2022-11-25T15:41:36Z")

</div>

The previous poster was trying to explain the colon to you without using a colon since it was confusing you I guess.

The colon is part of python’s slice index notation.

Here’s an article that explains how to use it (in short the number on the left of the colon is where the slicing begins and the number on the right is where it ends)

> **[Python Indexing and Slicing for Lists and other Sequential Types | Railsware...](https://railsware.com/blog/python-for-machine-learning-indexing-and-slicing-for-lists-tuples-strings-and-other-sequential-types/)**
>
> Python, one of the most in-demand machine learning languages, supports slice notation for any sequential data type like lists, strings, and others. Discover more about indexing and slicing operations over Python’s lists and any sequential data type

---

<div class="post-metadata">

**Author:** ![Atlas5779](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@Atlas5779](https://forum.freecodecamp.org/u/Atlas5779)\
**Post date:** [November 29, 2022, 9:01am UTC](https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628/6 "2022-11-29T09:01:57Z")

</div>

Thanks, slicing. That is all I needed to know. I have already studied slicing.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [May 30, 2023, 9:02pm UTC](https://forum.freecodecamp.org/t/what-is-the-colon-in-this-code-doing/572628/7 "2023-05-30T21:02:01Z")

</div>

Closed on May 30, 2023, 9:02pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
