[Tutor] (no subject)
Dirk Wangsadirdja
dirk at pensiun.com
Thu Sep 10 11:44:38 CEST 2009
I tested it and it works. But I dont understand why it works. Can
someone please explain it further? Thanks.
Alan Gauld wrote:
>
> "C or L Smith" <smiles at worksmail.net> wrote
>
>> Or (and I'll duck after I pass on what I just happened across today on
>> the web):
>>
>> ###
>> for i in range(len(word)):
>> print word[~i]
>> ###
>
> Neat trick!
> Now what does ~ do?... the bitwise inverse.
> So it relies on the rules of complementing the binary value
> to effectively add one and negate. Sneaky, and a new one on me!
>
> Alan G.
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list