Re: [Tutor] What's the logic behind parameters and arguments?
David wrote: Dear list readers, the command find() takes two parameters, start and end, e.g.: find(substring[, start[, end]]). Here, a substring is located UP TO BUT NOT INCLUDING the optional parameter 'end'. Compare this to replace(). replace() comes with the count argument, e.g.: replace(old, new[, count]) But here the substring is replaced UP TO AND INCLUDING to the optional argument count. My question is how I am best to make sense of this discrepancy. Is there any logic behind this that might make my life easier once I become aware of it? I know of the indexing rules, but this here is obviously not the same. I am curious... The two functions do different things, they work differently, they take different arguments. replace takes an inclusive `count` parameter because that's the most sensible and obvious way to implement a count parameter. "I want to replace the first five words" suggests a count parameter of 5, not 6. A count of 1 should replace 1 time, not 0 times. The start and end parameters of find work like slices, where the arguments act to slice *between* items: 0.1.2.3.4.5.6 |a|b|c|d|e|f| So, completely different, and there's no discrepancy. As for the question why replace doesn't take a start and end argument like find, *shrug* perhaps it should. But it already has three parameters, another two will start overloading it. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What's the logic behind parameters and arguments?
"Rafael Durán Castañeda" wrote I don't see discrepancy, end and count are two arguments than mean very different things. End is the position where find ends, it could be included or excluded, in this case is excluded. Count is the maximun number of substrings you want to replace, it wouldn't make sense count=6 if you want to replace 5. And in general Python uses the convention for *positional* values that it goes up to but not including the last position. Compare slicing, range() etc. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What's the logic behind parameters and arguments?
I don't see discrepancy, end and count are two arguments than mean very different things. End is the position where find ends, it could be included or excluded, in this case is excluded. Count is the maximun number of substrings you want to replace, it wouldn't make sense count=6 if you want to replace 5. 2011/3/29 David > Dear list readers, > > the command find() takes two parameters, start and end, e.g.: > > find(substring[, start[, end]]). > > Here, a substring is located UP TO BUT NOT INCLUDING the optional > parameter 'end'. > > Compare this to replace(). replace() comes with the count argument, e.g.: > > replace(old, new[, count]) > > But here the substring is replaced UP TO AND INCLUDING to the optional > argument count. > > My question is how I am best to make sense of this discrepancy. Is there > any logic behind this that might make my life easier once I become aware > of it? I know of the indexing rules, but this here is obviously not the > same. I am curious... > > Thanks, > > David > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] What's the logic behind parameters and arguments?
Dear list readers, the command find() takes two parameters, start and end, e.g.: find(substring[, start[, end]]). Here, a substring is located UP TO BUT NOT INCLUDING the optional parameter 'end'. Compare this to replace(). replace() comes with the count argument, e.g.: replace(old, new[, count]) But here the substring is replaced UP TO AND INCLUDING to the optional argument count. My question is how I am best to make sense of this discrepancy. Is there any logic behind this that might make my life easier once I become aware of it? I know of the indexing rules, but this here is obviously not the same. I am curious... Thanks, David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor