Indexing

To better understand how the indexing with a python list works, I tried this.
First, a = [0, 1, 2, 3, 4, 5].
1. a[4:6] gives [4, 5], as I learned before.
2. a[-1:2] gives [].
3. a[-2:] gives [4, 5].
4. a[-5:2] gives [1].
Here is my understanding. The zero and positive numbers counts elements from the left. The negative numbers counts from the right. When we write [ind1:ind2], the element indicated by ind1 should be on the left side of the element pointed by ind2.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s