Computer Forums Python Question?
 Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Log in

 Thread Tools Search this Thread Display Modes

 05-04-2013, 04:04 PM #1 Baseband Member     Join Date: Jan 2013 Location: United States Posts: 81 Python Question? Why does this start counting with 21? I understand that it's counting every fourth digit backward but I'm unsure why it starts with -21 x = list(range(22)) for i in x[::-4]: print i, __________________ __________________
 05-05-2013, 09:36 AM #2 Site Team     Join Date: Sep 2006 Posts: 10,720 Re: Python Question? I'm not sure why it'd start there, let alone be negative. From what I've seen on line, you should be starting at 0 and be able to go up to 21. You should never see a 22 unless you seeded the range function with a -22 to start with. __________________ __________________ "as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it" Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
 05-05-2013, 10:48 AM #3 Baseband Member     Join Date: Jan 2013 Location: United States Posts: 81 Re: Python Question? Thank you. I'll tinker with it a little more to see if I can figure it out. This one prints the same result: i = 0 x = list(range(0,22)) x.reverse() while i <= 21: print x[i] i += 4 both print: '21 17 13 9 5 1' in that order but i'm still confused why the first one starts with 21. If its range is '0-21' and I start counting backwards by four why is it starting with 21? I guess I'll be digging through 'Think Python' all day today. __________________
 05-05-2013, 01:05 PM #4 Site Team     Join Date: Sep 2006 Posts: 10,720 Re: Python Question? So when you reverse the list, it the list will then be 21, 20, 19..., 0 Since that loop starts at index 0 that's why the second code set produces those results. Why the first code set you gave is doing the same thing, that I'm not sure.. __________________ "as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it" Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 » Recent Threads

All times are GMT -5. The time now is 11:56 AM.

 -- Computer Forums -- Mobile Contact Us - Computer Forums - Archive - Community Rules - Terms of Service - Privacy - Top

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0