Question about properties.

Dustan DustanGroups at gmail.com
Fri Aug 10 08:36:23 EDT 2007


On Aug 10, 5:31 am, dijkstra.ar... at gmail.com wrote:
> On Aug 10, 12:21 pm, king kikapu <aboudou... at panafonet.gr> wrote:
>
>
>
> > Hi,
>
> > i read in a book the following code snippet that is dealing with
> > properties:
>
> > class ProtectAndHideX(object):
> >     def __init__(self, x):
> >         assert isinstance(x, int), '"x" must be an integer!"'
> >         self.__x = ~x
>
> >     def get_x(self):
> >         return ~self.__x
>
> >     x = property(get_x)
>
> > Can anyone please help me understand what the symbol "~" does here ??
>
> > Thanks for any help!
> >>> help(2)
>
> ....
>  |  __invert__(...)
>  |      x.__invert__() <==> ~x
>
> hth.
> Duikboot

http://docs.python.org/ref/unary.html

The unary ~ (invert) operator yields the bit-wise inversion of its
plain or long integer argument. The bit-wise inversion of x is defined
as -(x+1). It only applies to integral numbers.




More information about the Python-list mailing list