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" <smi...@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@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