Python Forum
For loop prints strane values?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loop prints strane values?
#3
You are misunderstanding indexes. 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
If you just give one index, you get the item after it. But if you give two indexes, you get everything between them. So lunch[0:5] is five items, not six.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
For loop prints strane values? - by colt - Sep-22-2019, 01:38 AM
RE: For loop prints strane values? - by Larz60+ - Sep-22-2019, 01:57 AM
RE: For loop prints strane values? - by ichabod801 - Sep-22-2019, 02:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through values and compare edroche3rd 6 789 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,351 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  zfill prints extra et the end of a var tester_V 4 1,019 Mar-24-2023, 06:59 PM
Last Post: tester_V
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,586 Jul-27-2022, 08:50 PM
Last Post: rob101
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,298 Jun-05-2022, 05:24 AM
Last Post: onenessboy
  Loop through values in dictrionary and find the same as in previous row Paqqno 5 1,994 Mar-27-2022, 07:58 PM
Last Post: deanhystad
  How to add for loop values in variable paulo79 1 1,526 Mar-09-2022, 07:20 PM
Last Post: deanhystad
  variable prints without being declared. ClockPillow 2 1,886 Jul-11-2021, 12:13 AM
Last Post: ClockPillow
Exclamation Compare values in a for loop. penahuse 1 2,440 Feb-22-2021, 07:01 AM
Last Post: buran
  Output prints Account.id at the end? LastStopDEVS 5 2,896 Dec-19-2020, 05:59 AM
Last Post: buran

Forum Jump:

User Panel Messages

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