Python Forum
Upper-Bound Exclusive Meaning
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upper-Bound Exclusive Meaning
#1
I'm not entirely sure if this topic should be posted in "General Coding Help," But I hope its fine.

What does Upper-Bound Exclusive mean?

Whilst taking lessons on Python, my Instructor said mid-sentence that, "...since the slicing syntax is upper-bound exclusive..."
Taken aback, I began researching what Upper-bound exclusive means, but to no avail.

If there are more important threads, I suggest you go there. This is not a enhancingly important thread, but I strive to understand Programming and what code does, therefore I'd appreciate it if someone could give me a explanation.

Thanks,
Johnny
Reply
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the meaning of the line of code. jahuja73 0 268 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index MadMacks 26 3,051 Mar-07-2023, 09:50 PM
Last Post: MadMacks
  Replace with upper(string) WJSwan 7 1,545 Feb-10-2023, 10:28 AM
Last Post: WJSwan
  Csv writer meaning of quoting mg24 2 1,105 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  AttributeError: 'list' object has no attribute 'upper' Anldra12 4 4,718 Apr-27-2022, 09:27 AM
Last Post: Anldra12
  meaning of -> syntax in function definition DrakeSoft 5 1,877 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Operator meaning explanation Sherine 3 1,980 Jul-31-2021, 11:05 AM
Last Post: Sherine
  parser.parse_args() meaning vinci 2 2,549 Oct-26-2020, 04:13 PM
Last Post: vinci
  How can I add string.upper() noahneature 2 1,834 Oct-11-2020, 06:41 PM
Last Post: noahneature
  What is the meaning of k in this function? giladal 3 2,652 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