Python Forum
"Up to but not including" (My personal guide on slicing & indexing)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Up to but not including" (My personal guide on slicing & indexing)
#6
(Nov-20-2019, 09:17 PM)Drone4four Wrote: From this code snippet, as you can see, if there is a single integer passed into the range() function, it starts at 0 and goes up to but does not include the final number in the generated list. In this way it's similar to list slicing. But when passing in parameters into randint(), the result includes any integer from the beginning parameter as well as up to (and including) the final integer at the end. This isn't quite as easy to remember.

Hi!

You could use mnemonics:
If you are a RANGER (for range()), you are a good guy, and don't reach the last limit ...
If you are RANDY (for randint()), you reach the limits ...

Angel Shifty Cool Tongue Big Grin

All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Messages In This Thread
RE: "Up to but not including" (My personal guide on slicing & indexing) - by newbieAuggie2019 - Nov-20-2019, 09:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function to count words in a list up to and including Sam Oldman45 15 6,534 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Complete Guide to Shodan Calli 4 2,253 Jul-18-2022, 04:29 PM
Last Post: Calli
  Including data files in a package ChrisOfBristol 4 2,534 Oct-27-2021, 04:14 PM
Last Post: ChrisOfBristol
  Not including a constructor __init__ in the class definition... bytecrunch 3 11,795 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  how to create pythonic codes including for loop and if statement? aupres 1 1,919 Jan-02-2021, 06:10 AM
Last Post: Gribouillis
  slicing and indexing a list example leodavinci1990 4 2,323 Oct-12-2020, 06:39 AM
Last Post: bowlofred
  Need to access Windows Machine or Personal Certificate Store and send to web app seswho 0 1,634 Sep-14-2020, 04:57 PM
Last Post: seswho
  New User online Guide NAP1947 1 1,539 Sep-06-2020, 04:36 PM
Last Post: Larz60+
  Including modules in Python using sys.path.append JoeDainton123 1 2,889 Aug-24-2020, 04:51 AM
Last Post: millpond
  Including a Variable In the HTML Tags When Sending An Email JoeDainton123 0 1,869 Aug-08-2020, 03:11 AM
Last Post: JoeDainton123

Forum Jump:

User Panel Messages

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