[Tutor] On slicing
If numbers=[1,2,3,4,5,6,7,8,9,10] and since "...any time the leftmost index in a slice comes later in the seqence than the second one... the result is always an empty sequence", why the slice numbers[10:0:-2] produces the sequence [10,8,6,4,2] but not the sequence []? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] On slicing
2009/9/17 Rich Lovely : > 2009/9/17 george fragos : >> If numbers=[1,2,3,4,5,6,7,8,9,10] and since "...any time the >> leftmost index in a slice comes later in the seqence than the second >> one... the result is always an empty sequence", why the slice >> numbers[10:0:-2] produces the sequence [10,8,6,4,2] but not the >> sequence []? >> ___ >> Tutor maillist - tu...@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > There should be a caveat to that: Unless the third index (step) is negative. > > The first value is start, the second stop, and the third step. What > you are saying with numbers[10,0,-2], is start at 10 (facing towards > the end of the sequence), keep going until you get to 0, taking two > steps backwards each time. > > I hope that clears things up a little.. > > -- > Rich "Roadie Rich" Lovely > > There are 10 types of people in the world: those who know binary, > those who do not, and those who are off by one. > Thanx for your reply...! By the way, I'd like to say hallo to the List and state that I'm just starting with Python...! George Fragos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Novice qustion
Hi all Pythons! I'm new to Python and this List! I'm reading Hetland's "Beginning Python" and I tried to test myself an example the book provides in 59: width = input('Please enter width: ') price_width = 10 item_width = width - price_width header_format = '%-*s%*s' format = '%-*s%*.2d' print '=' * width print haeder_format % (item_width, 'Item', price_width, 'Price') print '-' * width print format % (item_width, 'Apples', price_width, 0.4) print format % (item_width, 'Pears', price_width, 0.5) print format % (item_width, 'Cantaloupes', price_width, 1.92) print format % (item_width, 'Dried Apricots (16 gr)' price_width, 8) print format % (item_width, 'Prunes (4 Kgr)', price_width, 12) print '=' * width Trying to run this script (saved as "test.py")I receive this error message: a...@deadend:~/Desktop$ python test.py File "test.py", line 18 print format % (item_width, 'Dried Apricots (16 gr)' price_width, 8) ^ SyntaxError: invalid syntax I double checked my typing and I see no errors in it (I copied it from the book exactly as it is)! Are there any...? What's the "invalid" in my "syntax"? Thanx for the help! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Novice qustion
2009/9/24 Oxymoron : >> print format % (item_width, 'Cantaloupes', price_width, 1.92) >> print format % (item_width, 'Dried Apricots (16 gr)' price_width, 8) > > > Notice the line before (works) and after (doesn't work - as the interpreter > pointed out), how do you separate items in a tuple? :-) > > Did not check the rest of it. OK, I located the false syntax and I fixed it, thanx for your help! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor