# Coding with Strings

Strings are ordered sequences, so we can index and slice the string.&#x20;

We can use a square bracket notation to extract characters from the string, in the format \[start:stop:step].&#x20;

Consider the string “Greetings!” indexed from the start.

<table data-full-width="false"><thead><tr><th width="76" align="center"></th><th width="73" align="center"></th><th width="67" align="center"></th><th width="75" align="center"></th><th width="70" align="center"></th><th width="73" align="center"></th><th width="72" align="center"></th><th width="69" align="center"></th><th width="73" align="center"></th><th align="center"></th></tr></thead><tbody><tr><td align="center">0</td><td align="center">1</td><td align="center">2</td><td align="center">3</td><td align="center">4</td><td align="center">5</td><td align="center">6</td><td align="center">7</td><td align="center">8</td><td align="center">9</td></tr><tr><td align="center">G</td><td align="center">r</td><td align="center">e</td><td align="center">e</td><td align="center">t</td><td align="center">i</td><td align="center">n</td><td align="center">g</td><td align="center">s</td><td align="center">!</td></tr></tbody></table>

<figure><img src="https://83627414-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPIgwvqmDVAx1jR00FGa6%2Fuploads%2FzbolMzlA2FrQj2u1VUzv%2Fimage.png?alt=media&#x26;token=480b7953-d493-4691-8fa1-f775febb5b4d" alt=""><figcaption></figcaption></figure>

We can use forward or reverse indexing. Consider the string “Greetings!” indexed and sliced from the end.

<table data-full-width="false"><thead><tr><th width="76" align="center"></th><th width="73" align="center"></th><th width="67" align="center"></th><th width="75" align="center"></th><th width="70" align="center"></th><th width="73" align="center"></th><th width="72" align="center"></th><th width="69" align="center"></th><th width="73" align="center"></th><th align="center"></th></tr></thead><tbody><tr><td align="center">-10</td><td align="center">-9</td><td align="center">-8</td><td align="center">-7</td><td align="center">-6</td><td align="center">-5</td><td align="center">-4</td><td align="center">-3</td><td align="center">-2</td><td align="center">-1</td></tr><tr><td align="center">G</td><td align="center">r</td><td align="center">e</td><td align="center">e</td><td align="center">t</td><td align="center">i</td><td align="center">n</td><td align="center">g</td><td align="center">s</td><td align="center">!</td></tr></tbody></table>

<figure><img src="https://83627414-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPIgwvqmDVAx1jR00FGa6%2Fuploads%2FIKToZXjO3EC4CIsRY5gj%2Fimage.png?alt=media&#x26;token=2a2793da-e4a4-46be-b1aa-d5ad281c76c1" alt=""><figcaption></figcaption></figure>

I can also grab a single character.

<figure><img src="https://83627414-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPIgwvqmDVAx1jR00FGa6%2Fuploads%2FeikPrKLj0H1uNddsgYat%2Fimage.png?alt=media&#x26;token=7c7396bd-c3f7-4c34-b6e9-95c1e75ffcd3" alt=""><figcaption></figcaption></figure>

As discussed previously, strings are immutable, that means you cannot change the string. You can however slice the string and reassemble a new string with changes.

<figure><img src="https://83627414-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPIgwvqmDVAx1jR00FGa6%2Fuploads%2FphmfYbLrVgKgviTqmE0T%2Fimage.png?alt=media&#x26;token=2906ca50-008b-481a-a2dc-cbcdf05c31cf" alt=""><figcaption></figcaption></figure>

You cannot add a string and a number, they are different types. Examine the code below.

<figure><img src="https://83627414-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPIgwvqmDVAx1jR00FGa6%2Fuploads%2FvCvXHOYciqFMs4sw5vpK%2Fimage.png?alt=media&#x26;token=1f97423b-3d66-4453-8517-08af5f787566" alt=""><figcaption></figcaption></figure>
