Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > What's the difference between these 2 statements?

Reply
Thread Tools

What's the difference between these 2 statements?

 
 
Peter Otten
Guest
Posts: n/a
 
      04-20-2005
tiissa wrote:

> Peter Otten wrote:
>> http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>>
>>
>>>so if I want to reverse it fully using s[len(s)-1:-1] what would x be
>>>or is it impossible to express it in this way ?

>>
>>
>> This does not work for integers, because the theoretically correct value
>> x = -1 already has another interpretation as the gap between the last and
>> the last but one character.

> AFAIK, it is not an issue of integer (what else can an slice index be in
> python?) but simply of index aliasing.
>
> For x=-len(s)-1, you get the whole reversed list:
>
> In [5]: s[len(s)-1:-len(s)-1:-1]
> Out[5]: '54321'


Clever. I didn't think of that.
Still, for practical purposes you have to test for slicelen >= stringlen, so
whether you choose None, -len(s)-1, or -sys.maxint as the second slice
parameter doesn't matter much.

Peter

 
Reply With Quote
 
 
 
 
tiissa
Guest
Posts: n/a
 
      04-20-2005
Peter Otten wrote:
> Still, for practical purposes you have to test for slicelen >= stringlen, so
> whether you choose None, -len(s)-1, or -sys.maxint as the second slice
> parameter doesn't matter much.


Sure, for practical purposes you don't bother to write extra characters
and leave it void.
But we knew it from the start of the thread.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between between these "char"s arnuld C++ 33 03-05-2007 03:11 PM
what's the difference between these two methods? (aka, why doesn't one of them work?) JohnJSal Python 13 11-04-2006 08:17 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Difference between these two class declaration Rach Java 2 06-09-2004 11:50 AM
what is the difference between these two declarations Guybrush Threepwood C++ 7 02-26-2004 11:24 PM



Advertisments