Python Forum
Upper-Bound Exclusive Meaning
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upper-Bound Exclusive Meaning
#2
Say you have a slice from a to b (a:b). If you think of 0 being the index of the first item, 1 being the index of the second item, and so on, then a:b gets items with the indexes a, a + 1, a + 2, ..., b - 2, and b - 1. Note that b is not in that list. It is excluded, and it is the upper bound, so this is called upper bound exclusive.

I prefer to think of the indexes as being between the items, rather than on the items:

Output:
lunch = ['Spam', 'spam', 'spam', 'eggs', 'spam'] ^ ^ ^ ^ ^ ^ | | | | | | 0 1 2 3 4 5 -5 -4 -3 -2 -1
So if a is 1 and b is 4, you get the three items between 1 and 4 in the above diagram.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Upper-Bound Exclusive Meaning - by Johnny1998 - Aug-02-2019, 08:19 PM
RE: Upper-Bound Exclusive Meaning - by ichabod801 - Aug-02-2019, 08:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the meaning of the line of code. jahuja73 0 314 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index MadMacks 26 3,352 Mar-07-2023, 09:50 PM
Last Post: MadMacks
  Replace with upper(string) WJSwan 7 1,611 Feb-10-2023, 10:28 AM
Last Post: WJSwan
  Csv writer meaning of quoting mg24 2 1,165 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  AttributeError: 'list' object has no attribute 'upper' Anldra12 4 4,914 Apr-27-2022, 09:27 AM
Last Post: Anldra12
  meaning of -> syntax in function definition DrakeSoft 5 1,977 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Operator meaning explanation Sherine 3 2,053 Jul-31-2021, 11:05 AM
Last Post: Sherine
  parser.parse_args() meaning vinci 2 2,627 Oct-26-2020, 04:13 PM
Last Post: vinci
  How can I add string.upper() noahneature 2 1,876 Oct-11-2020, 06:41 PM
Last Post: noahneature
  What is the meaning of k in this function? giladal 3 2,746 Aug-15-2020, 12:32 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020