I am new learner and learning Python from a book.
I did what was written in the book....
I made a list like this below.....

```players = ['charles', 'martina', 'michael', 'florence', 'eli']
Then I wrote...
print(players[0:3])

#The results were like this....
['charles', 'martina', 'michael']```

So my question is this.... When we write the starting number (which is 0 in this case) we follow the "off by one" rule.... but when we write 3 as the end value... we have the third element!!!! Why do we not follow the "off by one" rule here?

Nov 15, 2020 in Python 540 views

## 1 answer to this question.

It's because of the way in which slicing notation works. [0:3] goes up to the 3rd element but does not include it. You can see this by slicing from the 3rd element until the end of the list
print(players[3:0])
#['florence, 'eli']

The 3 at the end is not the 3rd item in the list it is the 4th

• 65,890 points

## Why do we use return statement in python?

def maximum(x, y):     if x > y:     ...READ MORE

## How do I make one turtle follow another turtle in python?

Try something like this: from turtle import Turtle, ...READ MORE

## What do the three different types of brackets in Python code mean? I'm not sure if this is right, so if I'm wrong, please tell me:

[] - Normally used for dictionaries, list items () - ...READ MORE

+1 vote

## What do you mean by python scripting? What is a script and a module in python?

A module is a file containing a ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE