Python Substrings- Multiple Letters

In our prior lesson on Python strings , we indicate looked at how to create a string and how to reference individual characters in string.

Now, we’ll look at how to excerpt multiple characters from a string.  If you want to Python to talk about multiple letters, Python needs to know where to begin and where to end. So, you use indices as shown below. Look at the diagram below. The best way to figure this out is to run some code and explore a pattern:

The code above leads to the following console output:

substring-output

Below is a closer look at the heart of this code, showing each index.

python-substring-multiple-letters

As you can see below, there are 2 integers , that represent the where you want to start and end. The trickiest part is that the second number is not inclusive.

python-substring-multiple-letters-color-codedWhat if we only enter 1 number and a colon ?

The code above leads to the console output below :

console-output-strings

So, this is a handy shortcut when you know where you want to start in a string and you want to include all the characters through the end of the string.